-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.mjs
65 lines (57 loc) · 1.79 KB
/
webpack.config.mjs
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
/* ================================================= */
/* -- ES MODULE ---------------------------------- */
/* ================================================= */
console.log(`Using ${import.meta.url.split('/').slice(-1)}\n`);
import path from 'path';
import url from 'url';
// import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
// set NODE_ENV to 'development' by default
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
// is 'development' the current NODE_ENV?
const dev = process.env.NODE_ENV === 'development';
// `__dirname` is not a global variable in Node ES modules
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
// resolve full path of `part`, relative to 'src'
function resolvePath(a, b = '', c = ''){
return path.join(__dirname, a, b, c);
}
const config = {
mode: dev ? 'development' : 'production',
devtool: dev ? 'source-map' : undefined,
plugins: [
// new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({ template: resolvePath('src', 'index.html') }),
new MiniCssExtractPlugin()
],
entry: resolvePath('src', 'index.js'),
output: {
path: resolvePath('build'),
filename: 'app.js'
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx|json)$/,
include: [resolvePath('src')],
exclude: [/node_modules/, resolvePath('build')],
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
},
use: [
{ loader: 'babel-loader' }
]
},
{
test: /\.(css|scss|less)$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' },
]
}
]
}
};
export default config;