forked from AdamVig/battery-indicator-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·83 lines (77 loc) · 2.02 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const ENV = process.argv.find(arg => arg.includes('production')) ? 'production' : 'development'
const babelPresetEnvOptions = {
targets: {
esmodules: true
},
useBuiltIns: false,
// we use fast-async, it's faster than regenerator
exclude: ['transform-async-to-generator', 'transform-regenerator']
}
const templateHtmlMinifierOptions = {
modules: {
'lit-html': ['html'],
'lit-element': ['html', { name: 'css', encapsulation: 'style' }]
},
htmlMinifier: {
collapseWhitespace: true
}
}
const config = {
entry: './main.ts',
resolve: {
extensions: ['.js', '.ts']
},
output: {
filename: '[name].js',
path: path.resolve(process.cwd(), 'dist')
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', babelPresetEnvOptions]],
plugins: [
// Minify HTML and CSS in tagged template literals
['template-html-minifier', templateHtmlMinifierOptions],
// fast async uses Promise instead of regenerator to compile async functions
'module:fast-async'
]
}
},
{ loader: 'ts-loader' }
]
}
]
},
plugins: [
new HtmlWebpackPlugin({ template: 'index.html', inject: true })
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: true
})
]
},
devtool: ENV === 'development' ? 'inline-source-map' : 'source-map',
devServer: {
contentBase: process.cwd(),
compress: true,
port: 8080,
historyApiFallback: true,
stats: 'errors-only'
}
}
if (ENV === 'production') {
config.plugins.unshift(new CleanWebpackPlugin())
}
module.exports = config