forked from qgis/qwc2-demo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (102 loc) · 3.53 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
const webpack = require('webpack');
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const styleConfig = require("./styleConfig");
const styleReplacements = Object.keys(styleConfig).map(key => ({search: "@" + key + "@", replace: styleConfig[key], flags: "g"}));
const today = new Date();
const buildDate = today.getFullYear() + "." + String(1 + today.getMonth()).padStart(2, '0') + "." + String(today.getDate()).padStart(2, '0');
module.exports = (env, argv) => {
const isProd = argv.mode === "production";
return {
entry: {
App: path.resolve(__dirname, 'js', 'app.jsx')
},
output: {
path: path.resolve(__dirname, 'prod')
},
watchOptions: {
ignored: /node_modules(\\|\/)(?!qwc2)/
},
devtool: isProd ? 'source-map' : 'eval',
optimization: {
minimize: isProd
},
devServer: {
static: [
{
directory: path.resolve(__dirname, 'static'),
publicPath: '/'
}
],
compress: true,
hot: true,
port: 8080
},
resolve: {
extensions: [".mjs", ".js", ".jsx"],
fallback: {
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer/"),
path: require.resolve("path-browserify"),
timers: require.resolve("timers-browserify")
}
},
snapshot: {
managedPaths: [/(.*(\\|\/)node_modules(\\|\/)(?!qwc2))/]
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(argv.mode),
BuildDate: JSON.stringify(buildDate)
}
}),
new webpack.NormalModuleReplacementPlugin(/openlayers$/, path.join(__dirname, "qwc2", "libs", "openlayers")),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "index.html"),
build: buildDate
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'static' }
]
})
],
module: {
rules: [
{
test: /\.css$/,
use: [
{loader: 'style-loader'},
{loader: 'css-loader'},
{loader: 'string-replace-loader', options: {multiple: styleReplacements}}
]
},
{
test: /(.woff|.woff2|.png|.jpg|.gif)/,
type: 'asset/resource'
},
{
test: /\.jsx?$/,
exclude: /node_modules(\\|\/)(?!qwc2)/,
use: {
loader: 'babel-loader',
options: { babelrcRoots: ['.', path.resolve(__dirname, 'node_modules', 'qwc2')] }
}
},
{
test: /\.mjs$/,
type: 'javascript/auto'
},
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"]
}
]
}
};
};