forked from nadchif/html-duration-picker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
85 lines (81 loc) · 2.22 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
// webpack.config.js
const webpack = require('webpack');
const WebpackAutoInject = require('webpack-auto-inject-version');
const path = require('path');
const fs = require('fs');
const CreateFileWebpack = require('create-file-webpack');
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',
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',
// umdNamedDefine: true,
globalObject: 'this',
},
devServer: {
contentBase: path.join(__dirname, 'src'),
compress: true,
port: 9000,
open: true,
watchContentBase: true,
// public: require('os').hostname().toLowerCase() + ':9000',
disableHostCheck: true,
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]],
},
},
},
],
},
plugins: [
new webpack.DefinePlugin({
PICKER_STYLES_CSS_CONTENTS: JSON.stringify(pickerStyles),
}),
new WebpackAutoInject({
components: {
AutoIncreaseVersion: true,
InjectAsComment: false,
InjectByTag: true,
},
}),
new CreateFileWebpack({
path: './dist',
fileName: 'html-duration-picker.min.d.ts',
content: `declare module '${process.env.npm_package_name}'`,
}),
],
};
};