-
Notifications
You must be signed in to change notification settings - Fork 63
/
webpack.config.js
93 lines (90 loc) · 2.35 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
// webpack.config.js
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const CreateFileWebpack = require('create-file-webpack');
const TerserPlugin = require('terser-webpack-plugin');
const pickerStyles = fs
.readFileSync(path.join(__dirname, 'src', 'style.css'))
.toString()
.replace(/\n/gi, ''); // load styles.css
module.exports = (env, args) => {
const browserTarget =
env && env.target == 'ie'
? {
targets: {
chrome: '58',
ie: '9',
},
useBuiltIns: 'usage',
}
: {};
return {
context: __dirname,
entry: './src/html-duration-picker.js',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
output: {
path:
args.mode == 'development'
? path.resolve(__dirname, 'src/compiled')
: path.resolve(__dirname, 'dist'),
filename:
args.mode == 'development' ? 'html-duration-picker.js' : 'html-duration-picker.min.js',
library: 'HtmlDurationPicker',
libraryTarget: 'umd',
libraryExport: 'default',
globalObject: 'this',
},
devServer: {
static: path.join(__dirname, 'src'),
compress: true,
port: 9000,
open: true,
hot: true,
allowedHosts: 'all',
host: '127.0.0.1',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: ['babel-plugin-remove-template-literals-whitespace'],
presets: [['@babel/preset-env', browserTarget]],
},
},
},
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
search: '__RELEASE_VERSION__',
replace: process.env.npm_package_version,
flags: 'g',
},
},
],
},
plugins: [
new webpack.DefinePlugin({
PICKER_STYLES_CSS_CONTENTS: JSON.stringify(pickerStyles),
PICKER_RELEASE_VERSION: 'test ver',
}),
new CreateFileWebpack({
path: './dist',
fileName: 'html-duration-picker.min.d.ts',
content: `declare module '${process.env.npm_package_name}'`,
}),
],
};
};