-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
55 lines (51 loc) · 1.55 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
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import Path from 'path';
import Url from 'url';
// import webpack from 'webpack';
const projectFolder = Path.dirname(Url.fileURLToPath(import.meta.url));
console.log('NODE_ENV = "' + process.env.NODE_ENV + '"\n');
const devMode = process.env.NODE_ENV !== "production";
const styleLoaderRuleConfig = {
loader: 'style-loader',
options: {
injectType: "autoStyleTag",
},
};
export default {
entry: './src/index.js',
output: {
clean: true,
filename: 'main.js',
path: Path.resolve(projectFolder, 'dist'),
},
devtool: 'inline-source-map',
// devServer: {
// static: './dist',
// }
plugins: [
new HtmlWebpackPlugin({
template: './src/template.html',
scriptLoading: 'module',
}),
].concat(devMode ? [] : [new MiniCssExtractPlugin()]),
module: {
rules: [
{
// CSS files
test: /\.css$/i,
use: [
devMode ? styleLoaderRuleConfig : MiniCssExtractPlugin.loader,
'css-loader',
],
sideEffects: true, // Prevent tree shaking on css imports (in prod)
},
// {
// // Image files
// test: /\.(png|jpg|jpeg|svg|gif|webp)$/i,
// type: 'asset/resource',
// generator: { filename: 'static/[name][ext]'},
// },
],
},
}