-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
91 lines (88 loc) · 2.32 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
89
90
91
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = env => {
const isDev = env === 'dev';
const mode = isDev ? 'development' : 'production';
const minStr = isDev ? '' : '.min';
const watch = isDev;
const useAnalyzer = env.includes('analyze');
const builds = {
browser: {
mode,
entry: './src/client/index.js',
target: 'browserslist',
output: {
filename: `pdftest.client${minStr}.js`,
library: 'pdftest',
libraryTarget: 'umd',
umdNamedDefine: true,
},
resolve: {
fallback: { url: require.resolve('url') },
},
bundleAnalyzer: {
analyzerMode: useAnalyzer ? 'server' : 'disabled',
},
},
node: {
mode: 'development',
entry: './src/index.js',
target: 'node',
output: {
filename: 'pdftest.cjs.js',
libraryTarget: 'commonjs2',
},
externals: ['cors', 'express', 'fs', 'cross-fetch', 'path', /pdfjs/, 'pixelmatch'],
externalsType: 'commonjs',
babelOptions: {
presets: ['@babel/preset-env'],
targets: { node: "current" },
},
},
'chai-pdftest': {
mode,
entry: './src/frameworks/chai-pdftest.js',
target: 'browserslist',
output: {
filename: `chai-pdftest${minStr}.js`,
},
},
};
return Object.values(builds).map(build => ({
mode: build.mode,
entry: build.entry,
target: build.target,
watch: watch,
watchOptions: {
ignored: /node_modules/,
},
devtool: 'source-map',
output: {
path: path.resolve(__dirname, 'dist'),
...build.output,
},
node: false,
externals: build.externals,
externalsType: build.externalsType,
resolve: build.resolve,
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new BundleAnalyzerPlugin(build.bundleAnalyzer || { analyzerMode: 'disabled' }),
],
module: {
rules: [
{
test: /\.m?js$/,
exclude: new RegExp(path.join('node_modules', '(?!pixelmatch)').replace('\\', '\\\\')),
use: {
loader: "babel-loader",
options: build.babelOptions,
},
},
],
},
}));
};