generated from vaadin-component-factory/vcf-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
145 lines (137 loc) · 3.85 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
const { resolve, join } = require('path');
const merge = require('webpack-merge');
const { BabelMultiTargetPlugin } = require('webpack-babel-multi-target-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const BrotliPlugin = require('brotli-webpack-plugin');
const OUTPUT_PATH = resolve('build');
const INDEX_TEMPLATE = resolve('./demo/index.html');
const webcomponentsjs = './node_modules/@webcomponents/webcomponentsjs';
const assets = [
{
from: resolve('./demo/favicon.ico'),
to: OUTPUT_PATH
}
];
const polyfills = [
{
from: resolve(`${webcomponentsjs}/webcomponents-*.{js,map}`),
to: join(OUTPUT_PATH, 'vendor'),
flatten: true
},
{
from: resolve(`${webcomponentsjs}/bundles/*.{js,map}`),
to: join(OUTPUT_PATH, 'vendor', 'bundles'),
flatten: true
}
];
const commonConfig = merge([
{
entry: './demo/demo.js',
output: {
path: OUTPUT_PATH,
filename: '[name].[chunkhash:8].js'
},
module: {
rules: [
{
test: /\.js$/,
use: [BabelMultiTargetPlugin.loader(), 'uglify-template-string-loader']
}
]
},
plugins: [
new BabelMultiTargetPlugin({
babel: {
plugins: [
[
require('babel-plugin-template-html-minifier'),
{
modules: {
'@polymer/polymer/lib/utils/html-tag.js': ['html']
},
htmlMinifier: {
collapseWhitespace: true,
minifyCSS: true,
removeComments: true
}
}
]
],
presetOptions: { useBuiltIns: false }
},
safari10NoModuleFix: 'inline-data-base64',
targets: {
es6: {
browsers: [
'last 2 Chrome major versions',
'last 2 ChromeAndroid major versions',
'last 2 Edge major versions',
'last 2 Firefox major versions'
],
tagAssetsWithKey: false,
esModule: true
},
es5: {
browsers: ['ie 11'],
tagAssetsWithKey: true,
noModule: true
}
}
})
]
}
]);
const productionConfig = merge([
{
devtool: 'nosources-source-map',
optimization: {
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
output: {
comments: false
}
},
sourceMap: true,
parallel: true
})
]
},
plugins: [
new CopyWebpackPlugin([...polyfills, ...assets]),
new HtmlWebpackPlugin({
template: INDEX_TEMPLATE,
minify: {
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
}
}),
new HtmlReplaceWebpackPlugin([
{
pattern: /<script dev.*?src=".*?\.js".*?<\/script>/g,
replacement: ''
}
]),
new HtmlWebpackTagsPlugin({ tags: ['vendor/webcomponents-bundle.js'], append: false }),
new CompressionPlugin({ test: /\.js(\.map)?$/i }),
new BrotliPlugin({
asset: '[path].br[query]',
test: /\.js(\.map)?$/i,
threshold: 20,
minRatio: 0.8,
mode: 1
})
]
}
]);
module.exports = mode => {
return merge(commonConfig, productionConfig, { mode });
};