forked from miroapp/app-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (75 loc) · 1.9 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 HtmlWebpackPlugin = require('html-webpack-plugin')
const LocalTunnelPlugin = require('webpack-plugin-localtunnel')
const pkg = require('./package.json')
const subdomain = `${require('os').userInfo().username}-${pkg.name}`.replace(/(\s|\.)+/g, '-').toLowerCase()
const isProduction = process.env.NODE_ENV === 'production'
const isDevelopment = !isProduction
const entries = {
index: './src/index.ts',
app: './src/app.tsx',
}
module.exports = {
mode: isProduction ? 'production' : 'development',
bail: isProduction,
target: isDevelopment ? 'web' : 'browserslist',
devServer: {
noInfo: true,
disableHostCheck: true,
compress: true,
contentBase: path.join(__dirname, 'dist'),
port: 9000,
},
entry: entries,
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.css'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.svg/,
type: 'asset/source',
},
],
},
plugins: [
isDevelopment &&
new LocalTunnelPlugin({
subdomain,
}),
...Object.keys(entries).map((entry) => {
const sharedHtmlSettings = {
chunks: [entry],
inject: 'body',
meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'},
template: `./src/${entry}.html`,
}
return new HtmlWebpackPlugin({...sharedHtmlSettings, ...(entry === 'index' ? {} : {filename: `${entry}.html`})})
}),
].filter(Boolean),
}