-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
137 lines (132 loc) · 3.51 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// tslint:disable:no-implicit-dependencies
import * as path from "path";
import * as webpack from "webpack";
// webpack plugins
const CopyWebpackPlugin = require("copy-webpack-plugin");
// postcss plugins
const autoprefixer = require("autoprefixer");
const isProd = (): boolean => {
return process.env.NODE_ENV === "production";
};
const buildConfig: webpack.Configuration = {
entry: {
bundle: path.join(__dirname, "src/index.tsx"),
vendor_bundle: ["react", "react-dom", "bluebird", "ethereumjs-util"],
},
module: {
rules: [
// compile ts
{
exclude: /node_modules/,
loader: "ts-loader",
test: /\.tsx?$/,
},
// css loader
// source maps are generated only for dev builds
// css compression is only used for prod builds
{
test: /\.css$/,
use: [
{ loader: "style-loader", options: { sourceMap: !isProd() } },
{
loader: "css-loader", options: {
localIdentName: isProd() ? "[hash:base64]" : "[path][name]__[local]__[hash:base64:6]",
minimize: isProd(),
modules: true,
sourceMap: !isProd(),
},
},
{
loader: "postcss-loader",
options: {
plugins: () => [autoprefixer({
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9",
],
})],
sourceMap: !isProd(),
},
},
],
},
// file loader for media assets
{
exclude: [
/\.(html?)$/,
/\.(ts|tsx|js|jsx)$/,
/\.css$/,
/\.json$/,
],
loader: "file-loader",
query: {
name: "[hash].[ext]",
outputPath: "media/",
publicPath: "/",
},
},
],
} as webpack.NewModule,
output: {
filename: "[name].js",
publicPath: "/",
path: path.join(__dirname, "build/app"),
},
plugins: [
// exclude locale files in moment
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// pack vendor chunk
new webpack.optimize.CommonsChunkPlugin({
name: "vendor_bundle",
minChunks: Infinity,
}),
// copy files in public to build
new CopyWebpackPlugin([{
context: "public",
from: {
dot: false,
glob: "**/*",
},
to: path.join(__dirname, "build/app/"),
}]),
],
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
};
if (isProd()) {
// Production build tweaks
buildConfig.devtool = false;
buildConfig.plugins = (buildConfig.plugins || []).concat([
new webpack.DefinePlugin({
"process.env": { NODE_ENV: JSON.stringify("production") },
}),
// minify
new webpack.optimize.UglifyJsPlugin(),
]);
} else {
// Development build tweaks
const buildConfigModule = buildConfig.module as webpack.NewModule;
buildConfigModule.rules = (buildConfigModule.rules || []).concat([
// tslint
{
enforce: "pre",
exclude: /node_modules/,
loader: "tslint-loader",
test: /\.tsx?$/,
},
]);
buildConfig.plugins = (buildConfig.plugins || []).concat([
new webpack.DefinePlugin({
"process.env": { NODE_ENV: JSON.stringify("development") },
}),
// exclude source mapping for vendor libs
new webpack.SourceMapDevToolPlugin({
exclude: /^(vendor_).*\.js$/,
filename: "[file].map",
}),
]);
}
export default buildConfig;