-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (89 loc) · 2.77 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
/**
* Created by glenn on 01.06.16.
* Last updated on 04.11.20.
*/
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HelloWorldPlugin = require('./hello-world-plugin');
module.exports = (env) => {
const config = {
mode: eitherDevOrProd('development', 'production'),
entry: './demo/src/index.js',
output: {
filename: eitherDevOrProd('[name].js', '[name].[contenthash].js'),
path: path.resolve(__dirname, 'demo/dist'),
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: [
{
// https://webpack.js.org/loaders/babel-loader
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
{
loader: path.resolve('./'),
},
],
},
{
test: /\.html$/,
use: 'html-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
// Output Management
// https://webpack.js.org/guides/output-management/#setting-up-htmlwebpackplugin
// https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder
// Development
// https://webpack.js.org/guides/development/#using-watch-mode
new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
new HtmlWebpackPlugin({
template: './demo/src/index.tpl.html',
favicon: './demo/src/favicon.ico',
}),
new HelloWorldPlugin(),
],
optimization: {
// Caching
// https://webpack.js.org/guides/caching/#extracting-boilerplate
runtimeChunk: 'single',
},
devServer: {
contentBase: path.resolve(__dirname, 'demo/dist'),
compress: true,
noInfo: false,
historyApiFallback: true,
https: true,
hot: true,
publicPath: '/',
},
// Persistent Caching
// https://webpack.js.org/blog/2020-10-10-webpack-5-release/#persistent-caching
cache: {
// 1. Set cache type to filesystem
type: 'filesystem',
buildDependencies: {
// 2. Add your config as buildDependency to get cache invalidation on config change
config: [__filename],
// 3. If you have other things the build depends on you can add them here
// Note that webpack, loaders and all modules referenced from your config are automatically added
},
},
};
return config;
// Production
// https://webpack.js.org/guides/production/#specify-the-mode
function eitherDevOrProd(devStuff, prodStuff) {
return !(env && env.production) ? devStuff : prodStuff;
}
};