This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
94 lines (81 loc) · 2.47 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
// import plugins
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pages = require('./pug/config');
/**
* Base webpack configuration
*
* @param env -> env parameters
* @param argv -> CLI arguments, 'argv.mode' is the current webpack mode (development | production)
* @returns object
*/
module.exports = (env, argv) => {
let isProduction = (argv.mode === 'production');
let config = {
context: path.resolve(__dirname, "src"),
entry: {
'spectre': "./spectre.js",
'spectre.bundle': "./bundle.js",
'docs': [
"./docs/app.js",
"./docs/style.scss",
],
},
devtool: "inline-source-map",
devServer: {contentBase: "docs"},
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "../",
filename: (bundle) => {
let id = bundle.chunk.name;
return (id !== 'docs')
? "[name].js"
: "../docs/assets/[name].js";
}
},
plugins: [
new MiniCssExtractPlugin({
filename: "../docs/assets/style.css"
}),
...pages.map((page) => {
return new HtmlWebpackPlugin({
filename: `../docs/${page}.html`,
template: `../pug/pages/${page}.pug`,
inject: false,
})
}),
],
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin(),
new TerserPlugin(),
],
},
module: {
rules: [
{
test: /\.pug$/,
use: ['pug-loader'],
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
],
},
]
},
};
if (isProduction) {
config.plugins.push(
new CleanWebpackPlugin()
);
}
return config;
};