-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
87 lines (82 loc) · 1.84 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
const { join } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { DefinePlugin, BannerPlugin } = require('webpack');
require('dotenv').config();
function getDomain() {
const _url = process.env.DEBUG_URL;
const url = new URL(_url);
return url.origin;
}
const domain = getDomain();
const DEBUG_URLWithQuate = JSON.stringify(process.env.DEBUG_URL);
/**
* @type {import('webpack').Configuration}
*/
const config = {
mode: 'development',
entry: {
index: './src/iife.ts',
},
output: {
filename: '[name].js',
path: join(__dirname, 'dist'),
clean: true,
},
resolve: {
extensions: ['.ts', '.js'],
},
performance: {
maxAssetSize: 50000000,
maxEntrypointSize: 5000000,
},
module: {
rules: [
{
test: /\.tsx?/,
use: 'ts-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: join(__dirname, './dev/index.html'),
inject: 'body',
}),
new DefinePlugin({
__DOMAIN__: JSON.stringify(domain),
__DEBUG_URL__: DEBUG_URLWithQuate,
__ES6__: JSON.stringify(true),
__DEV__: JSON.stringify(true),
}),
new BannerPlugin({
banner: `(function(location) {
(() => {
const base = document.createElement('base');
base.href = ${DEBUG_URLWithQuate};
document.head.appendChild(base);
window.DEBUG_URL = ${DEBUG_URLWithQuate};
})();
`,
raw: true,
entryOnly: true,
}),
new BannerPlugin({
banner: `})(new URL(${JSON.stringify(process.env.DEBUG_URL)}));`,
raw: true,
entryOnly: true,
footer: true,
}),
],
devtool: 'source-map',
devServer: {
port: 9999,
proxy: [
{
context: ['/'],
target: domain,
changeOrigin: true,
},
],
},
};
module.exports = config;