-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
125 lines (122 loc) · 3.32 KB
/
webpack.config.js
File metadata and controls
125 lines (122 loc) · 3.32 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Webpack v4 configuration file.
*
* Use mode from env variable pass to webpack in order to
* differentiate build mode.
* Use a function that return configuration object based
* on env variable.
*
* Using Development
* - set webpack config mode to development
* - devtools will use source-map under package name;
*
* Using Production
* - set webpack config mode to production
* - change name of output file by adding .min
*
* Module export will output default value
* using libraryExport : 'default' for backward
* compatibility with previous release of the library.
*
* @type {webpack}
*/
const webpack = require('webpack');
const path = require('path');
// VUe file loader.
// const VueLoaderPlugin = require('vue-loader/dist/plugin').default;
const { VueLoaderPlugin } = require('vue-loader');
const TerserPlugin = require('terser-webpack-plugin');
const packageVersion = require('./package.json').version;
module.exports = (env) => {
// determine which mode
const isProduction = env.production || env.distribution;
const srcDir = path.resolve(__dirname, './src');
const outputDir = env.distribution ? path.resolve(__dirname, './dist') : path.resolve(__dirname, '../fohn-ui/public');
const libraryName = 'fohn';
const filename = libraryName + '-ui';
const prodPerformance = {
hints: false,
maxEntrypointSize: 640000,
maxAssetSize: 640000,
};
return {
entry: { [filename]: srcDir + '/fohn-ui.js' },
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? false : 'source-map',
performance: isProduction ? prodPerformance : {},
output: {
path: outputDir,
filename: isProduction ? '[name].min.js' : '[name].js',
library: libraryName,
libraryTarget: 'umd',
libraryExport: 'default',
umdNamedDefine: true,
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
},
},
},
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/,
},
// load .vue file
{
test: /\.vue$/,
loader: 'vue-loader',
},
// this will apply to both plain `.css` files
// AND `<style>` blocks in `.vue` files
{
test: /\.css$/,
use: [
// 'vue-style-loader',
'style-loader',
'css-loader',
],
},
],
},
externals: { jQuery: 'jQuery', fohn: 'fohn' },
resolve: {
alias: { vue$: 'vue/dist/vue.esm-bundler.js' },
modules: [
path.resolve(__dirname, 'src/'),
'node_modules',
],
extensions: [
'.json',
'.js',
'.vue',
],
},
plugins: [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(packageVersion),
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
}),
new VueLoaderPlugin(),
],
};
};