-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.prod.js
More file actions
90 lines (89 loc) · 2.65 KB
/
Copy pathwebpack.config.prod.js
File metadata and controls
90 lines (89 loc) · 2.65 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');
const { globSync } = require('glob');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pather = require('path');
module.exports = merge(common, {
mode: 'production',
watchOptions: {
ignored: ["**/node_modules", "**/dist"],
},
devServer: {
port: 8080,
hot: false,
liveReload: false,
devMiddleware: {
writeToDisk: true
},
},
//Add contenthash for cache busting
output: {
path: pather.resolve(__dirname, 'dist'),
filename: 'app.[contenthash].js',
},
plugins: [
//Find all HTML files and inject bundled CSS/JS link/script tags. Note Eleventy should be run first
...globSync("**/*.html", { cwd: './dist' }).map(pathToHtml => new HtmlWebpackPlugin({
template: './dist/' + pathToHtml,
filename: pathToHtml
})),
//Add contenthash for cache busting
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
//Removes any used CSS classes/fonts/etc. from the bundled css
new PurgeCSSPlugin({
paths: [...globSync("./src/**/*", { nodir: true }), "./node_modules/bootstrap/js/src/collapse.js", "./node_modules/bootstrap/js/src/dropdown.js", "./node_modules/bootstrap/js/src/tooltip.js"],
fontFace: true,
keyframes: true,
variables: true,
}),
],
module: {
rules: [
//Transpiles modern JS to older JS for compatibility with browsers specified in .browserslistrc
{
test: /\.(?:js|mjs|cjs)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
targets: "defaults",
presets: [
['@babel/preset-env', { "modules": false }]
]
}
}
},
//Loads SASS, adds polyfills/compatibility configs, transpiles to CSS, and finally extracts to separate CSS file
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
["postcss-preset-env"],
],
},
}
},
{
loader: "sass-loader",
options: {
sassOptions: {
quietDeps: true, // Silences warnings from node_modules
silenceDeprecations: ['import']
},
},
},
],
},
],
},
});