forked from eKoopmans/html2pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
82 lines (77 loc) · 2.25 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
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const pkg = require('./package.json');
const externals = [ 'jspdf', 'html2canvas' ];
const banner = `${pkg.name} v${pkg.version}
Copyright (c) ${(new Date).getFullYear()} Erik Koopmans
Released under the ${pkg.license} License.`;
module.exports = env => {
const isDev = env.dev;
const mode = isDev ? 'production' : 'development';
const watch = isDev;
const useAnalyzer = env.analyzer;
const makeUMDConfig = (filename, { bundle, min } = {}) => ({
output: {
filename,
library: {
name: 'html2pdf',
type: 'umd',
export: 'default',
umdNamedDefine: true,
}
},
target: 'browserslist',
externals: bundle ? [] : externals,
externalsType: 'umd',
optimization: { minimize: min },
devtool: min ? 'source-map' : false,
bundleAnalyzer: {
analyzerMode: useAnalyzer ? 'server' : 'disabled',
analyzerPort: 'auto',
defaultSizes: 'stat',
},
});
const builds = {
umd: makeUMDConfig('html2pdf.js'),
umdBundle: makeUMDConfig('html2pdf.bundle.js', { bundle: true }),
...(isDev ? {} : {
umdMin: makeUMDConfig('html2pdf.min.js', { min: true }),
umdBundleMin: makeUMDConfig('html2pdf.bundle.min.js', { bundle: true, min: true }),
}),
};
return Object.values(builds).map(build => ({
entry: './src/index.js',
mode,
target: build.target,
watch,
watchOptions: {
ignored: /node_modules/,
},
output: {
path: path.resolve(__dirname, 'dist'),
chunkFormat: false,
...build.output,
},
node: false,
externals: build.externals,
externalsType: build.externalsType,
optimization: build.optimization,
devtool: build.devtool || false,
plugins: [
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new webpack.BannerPlugin(banner),
new BundleAnalyzerPlugin(build.bundleAnalyzer || { analyzerMode: 'disabled' }),
],
experiments: build.experiments,
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
],
},
}));
};