-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
96 lines (94 loc) · 2.17 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
/* eslint-disable no-undef */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const portFinderSync = require('portfinder-sync');
const port = portFinderSync.getPort(8080);
// load local .env file
require('dotenv').config({ path: '.env' });
const templateParameters = process.env.BACKEND_URL
? require(`./src/assets/${process.env.DEFAULT_LANG || 'en'}.json`)
: require(`./src/assets/standalone.json`);
const hashFilenames = !(process.env.HASH_FILENAMES === 'false');
module.exports = {
mode: 'development',
entry: {
config: './src/assets/config.js',
bundle: './src/main.js',
embed: './src/embed.js',
wc: './src/wc.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: hashFilenames ? '[name].[contenthash].js' : '[name].js',
clean: true
},
module: {
rules: [
{
test: /\.css$/,
use: [
'to-string-loader',
{
loader: 'css-loader',
options: {
esModule: false
}
}
]
},
{
test: /\.(woff2|svg|webp|png)$/,
type: 'asset/inline'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
templateParameters: templateParameters,
chunks: ['config', 'bundle']
}),
new HtmlWebpackPlugin({
filename: 'embed.html',
template: 'src/embed.html',
templateParameters: templateParameters,
chunks: ['config', 'embed']
}),
new HtmlWebpackPlugin({
filename: 'embed/wrapper/index.html',
template: 'src/embedWrapper.html',
chunks: []
}),
new HtmlWebpackPlugin({
filename: 'wc/wrapper/index.html',
template: 'src/wcWrapper.html',
chunks: []
}),
new CopyPlugin({
patterns: [{ from: path.resolve(__dirname, './src/assets/favicon'), to: path.join('assets') }]
}),
new Dotenv()
],
devServer: {
static: './dist',
port: port,
client: {
overlay: {
runtimeErrors: true /** set to `false` if errors should be caught by the app instead */
}
}
},
resolve: {
alias: {
'@chunk': path.resolve(__dirname, './src/chunks')
},
fallback: {
https: false,
http: false,
buffer: false,
fs: false
}
}
};