-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
75 lines (67 loc) · 1.91 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
// webpack.config
'use strict'
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { format } = require('util')
const { resolve } = require('path')
const platforms = ['React', 'Svelte', 'Vue']
module.exports = env => {
const mode = env.mode || (env.production ? 'production' : 'development')
const { src } = env, l = src && src.length
const title = l && platforms.find(s => s.slice(0, l).toLowerCase() === src)
if (!title) {
process.stderr.write(
format('Unknown source: %o - use --env src=r|s|v\n', env.src))
process.exit(1)
}
const platform = title.toLowerCase()
const conf = {
devServer: {
port: 1111
},
entry: resolve(__dirname, 'src', 'start.' + platform + '.js'),
mode,
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
exclude: /node_modules/,
include: resolve(__dirname, 'src'),
test: /\.(jsx|js)$/,
use: [{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: 'defaults' }],
'@babel/preset-react'
]
}
}]
}
]
},
output: {
filename: 'static/[name].js',
globalObject: 'this',
path: resolve(__dirname, 'dist')
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.ejs',
templateParameters: { title }
}),
new MiniCssExtractPlugin({ filename: '[name].css' })
]
}
if (mode !== 'production') {
conf.devServer.hot = true
conf.devtool = 'inline-source-map'
conf.plugins.push(new CleanWebpackPlugin())
}
require(resolve(__dirname, 'webpack.' + platform))(conf)
return conf
}