forked from RobinHerbots/Inputmask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
130 lines (125 loc) · 2.83 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
var webpack = require("webpack"),
terserPlugin = require("terser-webpack-plugin"),
_ = require("lodash"),
fs = require("fs");
function createBanner() {
var pkg = JSON.parse(fs.readFileSync("./package.json"));
return "[name]\n" +
`${pkg.homepage}\n` +
`Copyright (c) 2010 - ${new Date().getFullYear()} ${pkg.author.name}\n` +
`Licensed under the ${pkg.license} license\n` +
`Version: ${pkg.version}`;
}
var rules = {
js: {
test: /\.js$/,
loader: "babel-loader",
exclude: /(node_modules)/,
options: {
presets: ["@babel/preset-env"],
plugins: ["@babel/plugin-transform-modules-commonjs"],
passPerPreset: true,
},
},
ts: {
test: /\.tsx?$/,
loader: "babel-loader",
exclude: /(node_modules)/,
options: {
presets: ["@babel/preset-typescript"],
passPerPreset: true,
},
}
};
module.exports = function (env, argv) {
var config = {
name: "main",
entry: {
"dist/inputmask": "./bundle.js",
"dist/inputmask.min": "./bundle.js",
"qunit/qunit": "./qunit/index.js"
},
output: {
path: __dirname,
filename: "[name].js",
libraryTarget: "umd",
globalObject: "this"
},
externals: {
"jquery": {
commonjs: "jquery",
commonjs2: "jquery",
amd: "jquery",
root: "jQuery"
},
"jqlite": "jqlite",
"qunit": "QUnit",
"window": "window"
},
optimization: {
minimize: env === "production",
minimizer: [new terserPlugin({
include: /\.min\.js$/,
terserOptions: {
sourceMap: env !== "production",
format: {
ascii_only: true,
beautify: false,
comments: /^!/
}
},
extractComments: false
}), new terserPlugin({
exclude: /\.min\.js$/,
terserOptions: {
sourceMap: env !== "production",
format: {
ascii_only: true,
beautify: true,
comments: /^!/
}
},
extractComments: false
})]
},
module: {
rules: [
rules.js,
rules.ts
]
},
resolve: {
extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
alias: {
// "./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
}
},
devtool: env === "production" ? undefined : "source-map",
plugins: [
new webpack.BannerPlugin({
banner: createBanner,
entryOnly: true
})
],
bail: true,
mode: env === "production" ? "production" : "none",
target: ["web", "es5"]
};
var jqueryConfig = _.defaultsDeep({}, config);
jqueryConfig.entry = {};
_.assignIn(jqueryConfig, {
name: "jquery",
resolve: {
extensions: [".wasm", ".mjs", ".js", ".ts", ".json"],
alias: {
"./dependencyLibs/inputmask.dependencyLib": "./dependencyLibs/inputmask.dependencyLib.jquery"
}
},
entry: {
"dist/jquery.inputmask": "./bundle.jquery.js",
"dist/jquery.inputmask.min": "./bundle.jquery.js",
"qunit/qunit": "./qunit/index.js"
}
});
return [config, jqueryConfig];
};