-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
102 lines (86 loc) · 2.86 KB
/
webpack.config.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
93
94
95
96
97
98
99
100
101
102
// Node.js modules
const path = require("path");
// Webpack plugins
const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const AssetsPlugin = require("assets-webpack-plugin");
// Environment variables
const ENV = process.env.npm_lifecycle_event;
const isProd = ENV === "build:prod";
var config = {
devtool: isProd ? "source-map" : "eval-source-map",
resolve: {
"extensions": [".js", ".jsx", ".json", ".css", ".html"],
"modules": ["./node_modules", "./src"]
},
entry: {
"app": ["./src/app/app.js"],
"vendors": ["./src/vendors.js"],
"polyfills": ["./src/polyfills.js"],
"styles": ["./src/styles.css"]
},
output: {
"path": isProd ? path.join(process.cwd(), "dist") : path.join(process.cwd(), "dist-dev"),
"filename": "[name].[hash].js",
"chunkFilename": "[hash].[name].js"
},
module: {
"rules": [
{
"test": /\.js$/,
"loader": "buble-loader",
"exclude": /node_modules/
},
{
"test": /\.css$/,
"use": ExtractTextPlugin.extract([
{
"loader": "css-loader",
"options": {
"sourceMap": true,
"minimize": isProd
}
},
{
"loader": "postcss-loader"
}
])
},
]
},
plugins: [
new ExtractTextPlugin("vendor.[hash].css"),
new CommonsChunkPlugin({
name: ["app", "vendors", "polyfills"]
}),
new HtmlWebpackPlugin({
"template": "./index.html",
"filename": "index.html",
"inject": "body"
}),
new AssetsPlugin({
path: path.join(process.cwd(), "dist"),
filename: 'webpack-assets.json',
prettyPrint: true
}),
new CopyWebpackPlugin([{
"from": "./src/assets",
"to": "assets"
}]),
],
devServer: {
historyApiFallback: true,
stats: "minimal"
}
};
if(isProd) {
const UglifyJsPlugin = require("webpack/lib/optimize/UglifyJsPlugin");
const NoEmitOnErrorsPlugin = require("webpack/lib/NoEmitOnErrorsPlugin");
const OptimizeJsPlugin = require("optimize-js-plugin");
Array.prototype.push.apply(config.plugins, [new UglifyJsPlugin(),
new NoEmitOnErrorsPlugin(),
new OptimizeJsPlugin()]);
}
module.exports = config;