-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
74 lines (70 loc) · 1.97 KB
/
webpack.config.js
File metadata and controls
74 lines (70 loc) · 1.97 KB
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
const path = require('path');
// include the js minification plugin
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// include the css extraction and minification plugins
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pages = ["home", "thank-you"];
const NewHtmlWebpackPlugin = pages.map(
(page) =>
new HtmlWebpackPlugin({
inject: 'body',
template: `./pages/${page}.html`,
filename: `./templates/${page}.html`
})
);
module.exports = {
entry: ['./src/js/index.js', './src/scss/index.scss'],
output: {
filename: './build/js/app.min.js',
path: path.resolve(__dirname)
},
module: {
rules: [
// perform js babelization on all .js files
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['babel-preset-env']
}
}
},
// compile all .scss files to plain old css
{
test: /\.(sass|scss)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
}
]
},
plugins: [
// extract css into dedicated file
new MiniCssExtractPlugin({
filename: './build/css/main.min.css'
}),
// clean out build directories on each build
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['./build/js/*', './build/css/*']
}),
new HtmlWebpackPlugin({
inject: 'body',
template: './pages/index.html',
filename: 'index.html',
})
].concat(NewHtmlWebpackPlugin),
optimization: {
minimizer: [
// enable the js minification plugin
new UglifyJSPlugin({
cache: true,
parallel: true
}),
// enable the css minification plugin
new OptimizeCSSAssetsPlugin({})
]
}
};