-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
103 lines (94 loc) · 2.91 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
103
/**
* wagtail-webpack config
* Adam Mateusz Brożyński 2024
* MIT License
*/
'use strict'
const path = require('path')
// Autoprefixer for writing CSS rules without vendor prefixes
const autoprefixer = require('autoprefixer')
// MiniCssExtractPlugin for combining output css files
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// CopyWebpackPlugin to copy assets that do not need to be compiled
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
// `production` mode results in minified output files
mode: 'production',
performance: {
// Warn us when output file > 512KB
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
entry: {
/*
* Instead of putting source static files to default `app/app/static` folder,
* we create `app/app/assets` folder where we will have our entypoints,
* js, sass files, images, etc. Webpack will compile entypoints and sass files,
* and copy `img/*` to `app/app/static folder`. In production mode,
* Wagtail will copy all of this to `/app/static`.
* Because of this we can simply use {% static 'app.js' %} in template.
* We use two entrypoints for frontend (`app.js`) and backend (`admin.js`)
*/
app: path.resolve(__dirname, 'app/assets/app.js'),
admin: path.resolve(__dirname, 'app/assets/admin.js'),
},
output: {
// Generate app.js and admin.js
filename: (pathData) => {
return pathData.chunk.name === 'app' ? 'app.js' : 'admin.js';
},
// set chunks names
chunkFilename: "[id]-[chunkhash].js",
// set output path to `app/static` (default for STATICFILES_DIRS defined in base.py)
path: path.resolve(__dirname, 'app/static')
},
devServer: {
// Run dev server with hot reload and writing output files to disk
port: 8001,
compress: true,
hot: true,
devMiddleware: {
writeToDisk: true
}
},
module: {
rules: [
// Compile and load imported sass files to css
{
test: /\.(scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'postcss-loader',
'sass-loader',
],
},
],
},
plugins: [
// Generate app.css and admin.css
new MiniCssExtractPlugin({
filename: (pathData) => {
return pathData.chunk.name === 'app' ? 'app.css' : 'admin.css';
},
}),
// Copy img folders to static (we use `context` to keep structure)
new CopyWebpackPlugin({
patterns: [
{
from: '*',
context: path.resolve(__dirname, 'app/assets/img'),
to: path.resolve(__dirname, 'app/static/img/'),
noErrorOnMissing: true,
},
{ from: '*',
context: path.resolve(__dirname, 'app/assets/admin/img'),
to: path.resolve(__dirname, 'app/static/admin/img/'),
noErrorOnMissing: true,
},
],
})
]
}