-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
80 lines (75 loc) · 2.02 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
const path = require('path')
const os = require('os')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
console.log(`run on ${os.cpus().length} CPUs`)
const webpackConfig = {
entry: {
index: './src/index.ts',
main: './example/main.ts',
client: './example/client.ts',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd',
},
devtool: 'source-map',
devServer: {
static: path.resolve(__dirname, 'example'),
hot: true,
},
mode: 'development',
cache: {
type: 'filesystem',
},
plugins:
process.env.NODE_ENV !== 'production'
? [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'example/main.ejs',
chunks: ['main'],
buildTime: new Date().toLocaleString(),
env: process.env.NODE_ENV,
}),
new HtmlWebpackPlugin({
filename: 'client.html',
template: 'example/client.ejs',
chunks: ['client'],
buildTime: new Date().toLocaleString(),
env: process.env.NODE_ENV,
}),
]
: [],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
},
],
},
}
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'demo') {
webpackConfig.mode = 'production'
webpackConfig.cache = false
delete webpackConfig.devtool
webpackConfig.plugins.unshift(new CleanWebpackPlugin())
if (process.env.NODE_ENV === 'demo') {
webpackConfig.plugins.push(
new CopyPlugin({ patterns: [{ from: 'example/simplepeer.min.js', to: 'simplepeer.min.js' }] }),
)
}
}
if (process.env.NODE_ENV === 'production') {
delete webpackConfig.entry.main
delete webpackConfig.entry.client
} else {
delete webpackConfig.entry.index
}
module.exports = webpackConfig