-
Notifications
You must be signed in to change notification settings - Fork 100
/
webpack.config.js
61 lines (59 loc) · 1.74 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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = (env, argv) => ({
mode: env.prod ? 'production' : 'development',
entry: path.resolve(__dirname, env.prod ? 'src/datepicker.js' : 'sandbox/sandbox.js'),
target: 'web',
output: env.prod ? {
path: path.resolve(__dirname, 'dist'),
library: 'datepicker', // The name of the global variable the library is set to.
libraryExport: 'default',
libraryTarget: 'umd', // "Universal" export - Node, browser, amd, etc.
filename: 'datepicker.min.js'
} : {},
devServer: {
open: true,
contentBase: path.resolve(__dirname, './sandbox'),
host: '0.0.0.0', // Allow viewing site locally on a phone.
port: 9001,
public: 'http://localhost:9001'
},
module: {
rules: [
{
test: /\.(scss|css)$/i,
use: [
MiniCssExtractPlugin.loader, // https://goo.gl/uUBr8G
'css-loader',
'postcss-loader', // https://goo.gl/BCwCzg - needs to be *after* `css-loader`.
'sass-loader'
]
}
]
},
optimization: {
minimize: !!env.prod,
minimizer: [
new TerserPlugin({ // https://goo.gl/YgdtKb
parallel: true, //https://goo.gl/hUkvnK
terserOptions: { // https://goo.gl/y3psR1
ecma: 5,
output: {
comments: false
}
}
})
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'datepicker.min.css'
}),
!env.prod && new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'sandbox/index.ejs'),
title: 'Datepicker Sandbox'
})
].filter(Boolean)
})