-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
webpack.config.js
109 lines (106 loc) · 2.58 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
var webpack = require("webpack");
const TerserJsPlugin = require("terser-webpack-plugin");
var libraryName = require("./package.json").name;
var withLocalesSuffix = "-i18n";
var fs = require("fs");
var path = require("path");
var entryPoints = {
[libraryName]: "./src/cronstrue.ts",
[libraryName + ".min"]: "./src/cronstrue.ts",
[libraryName + withLocalesSuffix]: "./src/cronstrue-i18n.ts",
[libraryName + withLocalesSuffix + ".min"]: "./src/cronstrue-i18n.ts",
};
var localeEntryPoints = {};
for (let locale of fs.readdirSync("./src/i18n/locales")) {
const code = path.basename(locale, path.extname(locale));
localeEntryPoints[`locales/${code}`] = "./src/i18n/locales/" + locale;
localeEntryPoints[`locales/${code}.min`] = "./src/i18n/locales/" + locale;
}
module.exports = [
{
mode: "production",
entry: entryPoints,
output: {
path: __dirname + "/dist",
filename: "[name].js",
library: libraryName,
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "globalThis",
},
resolve: {
extensions: [".js", ".ts"],
},
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserJsPlugin({
include: /\.min\.js$/,
}),
],
},
},
{
mode: "production",
entry: localeEntryPoints,
output: {
path: __dirname,
filename: "[name].js",
library: "[name]",
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "globalThis",
},
resolve: {
extensions: [".js", ".ts"],
},
externals: {
cronstrue: "cronstrue",
},
module: {
rules: [
{
test: /i18n[\/\\]locales/,
loader: "custom-loader",
options: {
process: function (resourcePath, source) {
let localeCode = resourcePath.match(/i18n[\/\\]locales[\/\\]([a-zA-Z_]+)\.ts$/)[1];
source = `\
var exports = __webpack_exports__;
${source}
import cronstrue from \"cronstrue\";
cronstrue.locales["${localeCode}"] = new ${localeCode}();
`;
return source;
},
},
},
{
test: /\.ts$/,
loader: "ts-loader",
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserJsPlugin({
include: /\.min\.js$/,
}),
],
},
resolveLoader: {
alias: {
"custom-loader": path.resolve(__dirname, "./webpack-custom-loader"),
},
},
},
];