This repository has been archived by the owner on Oct 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
102 lines (94 loc) · 2.38 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
const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ImageminPlugin = require('imagemin-webpack-plugin').default
const webpack = require('webpack');
const glob = require("glob");
const fs = require("fs");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const basePlugins = [
new HtmlWebpackPlugin({
template: "./app/index.html",
filename: "index.html",
inject: false,
chunks: ["app"],
}),
new webpack.ProvidePlugin({
moment: "moment",
"window.moment": "moment"
}),
new webpack.ProvidePlugin({
_: "underscore",
"window._": "_"
}),
new CopyWebpackPlugin([
{ from: "./app/views", to: "./views/" },
{ from: "./app/translations", to: "./translations/" },
{ from: "./app/images", to: "./images/" },
{ from: "./app/styles", to: "./styles/" },
{ from: "./app/fonts", to: "./fonts/" }
])
]
const prodPluginsBefore = [
new webpack.DefinePlugin({
__CONFIG__: fs.readFileSync("./config/prod.json", "utf8")
})
]
const devPluginsBefore = [
new webpack.DefinePlugin({
__CONFIG__: fs.readFileSync("./config/dev.json", "utf8")
})
]
const prodPluginsAfter = [
new ImageminPlugin({
test: /\.(jpe?g|png|gif|svg)$/i,
disable: process.env.NODE_ENV !== 'production', // Disable during development
pngquant: {
quality: '95-100'
}
})
];
const devPluginsAfter = [];
const buildPlugins = function(mode){
let PRODUCTION = false;
if(mode === "production"){
PRODUCTION = true;
}
const plugins = []
.concat(PRODUCTION ? prodPluginsBefore : [])
.concat(!PRODUCTION ? devPluginsBefore : [])
.concat(basePlugins)
.concat(PRODUCTION ? prodPluginsAfter : [])
.concat(!PRODUCTION ? devPluginsAfter : []);
return plugins;
};
module.exports = (env, argv) => ({
entry: {
"app": [
"./app/scripts/app.js",
]
},
output: {
path: path.join(__dirname, "dist"),
filename: "js/[name].js",
// publicPath: "/",
chunkFilename: "js/[name].js",
},
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
},
plugins: buildPlugins(argv.mode),
// optimization: {
// splitChunks: {
// chunks: 'initial'
// }
// }
});