-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.production.js
92 lines (88 loc) · 2.33 KB
/
webpack.config.production.js
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
var webpack = require("webpack");
var path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
// variables
var sourcePath = path.join(__dirname, "./src/frontend");
var outPath = path.join(__dirname, "./dist/frontend");
// plugins
var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
context: sourcePath,
entry: {
main: "./index.ts"
},
output: {
path: outPath,
filename: "[name].js",
chunkFilename: "[name].js", // or whatever other format you want.
publicPath: "/"
},
target: "web",
resolve: {
extensions: [".js", ".ts", ".tsx"],
// Fix webpack's default behavior to not load packages with jsnext:main module
// (jsnext:main directs not usually distributable es6 format, but es6 sources)
mainFields: ["module", "browser", "main"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: ["awesome-typescript-loader"]
},
// static assets
{ test: /\.html$/, use: "html-loader" },
{ test: /\.png$/, use: "url-loader?limit=10000" },
{ test: /\.jpg$/, use: "file-loader" }
]
},
optimization: {
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true
},
sourceMap: true
})
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
}
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.LoaderOptionsPlugin({
options: {
context: sourcePath
}
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new HtmlWebpackPlugin({
template: "assets/index.html",
inject: "body",
filename: "index.html"
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
// new BundleAnalyzerPlugin()
],
node: {
// workaround for webpack-dev-server issue
// https://github.com/webpack/webpack-dev-server/issues/60#issuecomment-103411179
fs: "empty",
net: "empty"
}
};