forked from twikoojs/twikoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
88 lines (86 loc) · 2.49 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
88
const path = require('path')
const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const ROOT_PATH = path.resolve(__dirname)
const BUILD_PATH = path.resolve(ROOT_PATH, 'dist')
const version = require('./package.json').version
const TerserPlugin = require('terser-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const banner =
'Twikoo v' + version + '\n' +
'(c) 2020-' + new Date().getFullYear() + ' iMaeGoo\n' +
'Released under the MIT License.\n' +
'Last Update: ' + (new Date()).toLocaleString()
function getConfig ({ extractCss }) {
return {
module: {
rules: [
{ test: /\.vue$/, loader: 'vue-loader' },
extractCss
? { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }
: { test: /\.css$/, use: ['vue-style-loader', 'css-loader'] },
{ test: /\.svg$/, loader: 'svg-inline-loader' },
{ test: /\.js$/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], plugins: ['@babel/plugin-transform-modules-commonjs', '@babel/transform-runtime'] } } }
]
},
entry: extractCss
? {
twikoo: './src/client/main.all.js'
}
: {
twikoo: './src/client/main.js',
'twikoo.all': './src/client/main.all.js'
},
output: {
path: BUILD_PATH,
filename: extractCss ? '[name].nocss.js' : '[name].min.js',
library: 'twikoo',
libraryTarget: 'umd',
globalObject: 'this'
},
target: ['web', 'es5'],
plugins: [
new webpack.BannerPlugin(banner),
new CopyPlugin({
patterns: [
{ from: 'demo/', to: './' }
]
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin(),
new TerserPlugin({
parallel: 4,
terserOptions: {
ecma: 5,
toplevel: true,
ie8: true,
safari10: true
}
})
],
devServer: {
static: [{
directory: BUILD_PATH,
publicPath: '/dist/',
serveIndex: true,
watch: true
}],
port: 9820,
host: 'localhost',
open: true,
hot: true,
compress: true
},
performance: {
maxEntrypointSize: 524288,
maxAssetSize: 524288
}
}
}
module.exports = process.env.NODE_ENV === 'production'
? [
getConfig({ extractCss: false }),
getConfig({ extractCss: true })
]
: getConfig({ extractCss: false })