-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
webpack.config.js
79 lines (73 loc) · 1.86 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
const webpack = require('webpack'); // to access built-in plugins
const path = require('path');
const publicDir = path.join(__dirname, 'public');
const distDir = path.join(__dirname, 'dist');
const CopyPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const WebpackModules = require('webpack-modules');
const CompressionPlugin = require('compression-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const widgetConfig = require('./widget.config.json');
const pkg = require('./package.json');
const defaultConfig = {
mode:'production',
devServer: {
static: distDir,
port: 9000
},
plugins: [
new webpack.ProgressPlugin(),
new WebpackModules(),
new CleanWebpackPlugin({ protectWebpackAssets: false }),
new CopyPlugin([{ from: 'public', to: '.' }]),
new CompressionPlugin()
],
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat'
}
}
};
const widgetFilename = widgetConfig.semanticReleases
? `${widgetConfig.widgetName}-${pkg.version}.js`
: `${widgetConfig.widgetName}.js`;
module.exports = [
{
...defaultConfig,
target: 'web',
optimization: {
minimizer: [new UglifyJsPlugin()]
},
entry: './src/EmbeddableWidget.tsx',
output: {
path: distDir,
publicPath: '/',
filename: widgetFilename,
libraryTarget: 'module',
module: true
},
experiments:{
outputModule: true
}
}
];