-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
79 lines (77 loc) · 2.16 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
const path = require("path");
const webpack = require("webpack");
const CleanPlugin = require("clean-webpack-plugin").CleanWebpackPlugin;
const HTMLPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = (env, argv) => {
const modeIsProd = argv.mode === "production";
return {
entry: ["babel-polyfill", "./src/js/app.js"],
output: {
path: path.join(__dirname, "dist"),
filename: "js/bundle.js"
},
devtool: modeIsProd ? false : "cheap-eval-source-map",
devServer: {
port: "1111",
contentBase: "./dist"
},
plugins: [
new CleanPlugin(),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(modeIsProd ? "production" : "development"),
APP_URL: JSON.stringify(modeIsProd ? "https://subject026.github.io/dropbox-todos/" : "http://localhost:1111"),
BUILD_TIME_STAMP: modeIsProd ? Date.now() : false
}),
new HTMLPlugin({
filename: "index.html",
template: "./src/index.html"
}),
new MiniCSSExtractPlugin({
filename: "app.css"
// chunkFilename: "[id].css"
}),
new WorkboxPlugin.InjectManifest({
swSrc: "./src/src-sw.js",
swDest: "sw.js"
}),
new CopyPlugin([
{
from: modeIsProd ? "./src/manifest.json" : "./src/manifest-dev.json",
to: "manifest.json"
},
{
from: "./src/images",
to: "images"
}
])
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: [
{
loader: MiniCSSExtractPlugin.loader,
options: {
hmr: modeIsProd ? false : true
}
},
"css-loader",
"sass-loader"
]
}
]
}
};
};