-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
153 lines (142 loc) · 5.22 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/****************************************************
*
* WEBPACK CONFIGURATION FILE
* (to build a busy browser bundle in "dist" folder)
*
***************************************************/
'use strict';
const webpack = require('webpack');
const packageJson = require('./package.json');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); // creates index.html in web/public directory
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanObsoleteChunks = require('webpack-clean-obsolete-chunks'); // removes obsolete hashed files = require(previous builds
const TerserPlugin = require('terser-webpack-plugin');
const postCssLoader = {
loader: 'postcss-loader', // adds browser specific prefixes for improved html5 support
options: {
postcssOptions: {
plugins: [ 'autoprefixer' ]
}
},
};
const babelLoader = {
loader: 'babel-loader',
options: {
babelrc: false,
plugins: [
[
'@babel/plugin-transform-runtime',
{
'absoluteRuntime': false,
'corejs': false,
'helpers': false,
'regenerator': true,
'useESModules': true,
'version': "^7.8.4"
}
]
], // solves regenerator runtime errors with dynamic imports
presets: [
[
'@babel/preset-env',
{
targets: '> 1.5%, not dead',
modules: false, // by default, Babel rewrites modules to use CommonJS, which won’t tree-shake!
},
]
],
cacheDirectory: true, // speeds up babel compilation (default cache: node_modules/.cache/babel-loader)
}
};
const sourcePath = './src/';
module.exports = (env, argv) => {
const isDev = argv.mode !== 'production';
console.warn(`\n\n\n============================================================`);
console.info(`Building core busy bundle version: ${packageJson.version} for ${isDev ? 'development' : 'production'}...`);
console.warn(`============================================================`);
return {
entry: './src/busy-global.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'busy.js',
publicPath: '/', // where browser will request the webpack files
chunkFilename: 'chunk_[name].js' // chunk filename
},
watch: isDev,
devtool: isDev ? 'source-map' : false, // useful for debugging.
performance: { hints: false }, // prevent webpack logging warnings for bundles > 200kb
optimization: {
minimize: !isDev,
minimizer: [
new TerserPlugin({ // js parser, mangler and compressor toolkit for ES6+
parallel: true,
extractComments: false, // don't extract code comments (ie licence agreements) to a separate text file
terserOptions: {
format: { comments: false },
ecma: 5,
mangle: false
},
}),
],
},
module: {
rules: [
// css
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader', // translates CSS into CommonJS
postCssLoader,
],
},
// js
{
test: /\.js$/,
exclude: /node_modules/,
use: [ babelLoader ]
},
// stylus
{
test: /\.styl$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
'css-loader', // translates CSS into CommonJS
postCssLoader, // allows es6 css imports
'stylus-loader', // compiles stylus into CSS
],
},
// svg assets
{
test: /\.svg$/,
loader: 'svg-inline-loader'
}
]
},
plugins: [
new CleanObsoleteChunks(), // removes obsolete hashed files from previous builds
new HtmlWebpackPlugin({
template: sourcePath + 'index.html',
minify: !isDev && {
html5: true,
caseSensitive: true,
removeComments: true,
},
}),
new MiniCssExtractPlugin({
filename: 'index.css',
chunkFilename: 'chunk_[name].css',
}),
new webpack.BannerPlugin({
banner: `
@aamasri/busy package version ${packageJson.version}
(c) 2023 Ananda Masri
Released under the MIT license
https://auro.technology/demos/busy-js
`
})
]
};
};