-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.lib.config.js
75 lines (74 loc) · 1.89 KB
/
webpack.lib.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
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin-legacy')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const elementExternals = require('./elementUIDependencies')
const components = require('./components')
const externals = {
vue: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue',
},
lodash: {
root: '_',
commonjs: 'lodash',
commonjs2: 'lodash',
amd: 'lodash',
},
axios: 'axios',
elementThemeChalk: 'element-theme-chalk',
}
elementExternals.components.forEach(function(key) {
externals[`element-ui/lib/${key}`] = `element-ui/lib/${key}`
})
Object.keys(components).forEach(function(key) {
if (key === 'index') {
return
}
const sourcePath = components[key]
.replace('index.vue', '')
.replace('index.js', '')
.replace('.vue', '')
.replace('.js', '')
externals[sourcePath] = `dynamic-form-render/dist/lib/${key}`
})
module.exports = {
productionSourceMap: false,
chainWebpack: config => {
config.entryPoints.delete('app')
config.plugin('extract-css').tap(options => {
options[0] = {
filename: 'css/index.css',
chunkFilename: 'css/index.css',
}
return options
})
if (process.env.npm_config_report === 'true') {
config.plugin('bundleAnalyzer').use(BundleAnalyzerPlugin)
}
},
configureWebpack: {
entry: components,
output: {
path: path.join(__dirname, 'dist'), //this one sets the path to serve
filename: 'lib/[name].js',
library: 'dynamicFormRender',
libraryTarget: 'commonjs2',
},
optimization: {
minimize: true,
splitChunks: false,
},
resolve: {
alias: require('./alias.config.js').webpack,
},
plugins: [
new TerserPlugin({
terserOptions: {compress: {drop_console: true}},
}),
],
externals: externals,
},
}