-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.pime.js
More file actions
156 lines (148 loc) · 3.77 KB
/
Copy pathwebpack.config.pime.js
File metadata and controls
156 lines (148 loc) · 3.77 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
// Patch RegExp so that the 's' (dotAll) flag does not throw on old Node.js.
// The snippet runs before any webpack module is evaluated.
// It wraps the native RegExp: when the 's' flag is requested, it strips the
// flag from the constructor call and replaces every unescaped '.' in the
// source with '[\s\S]' (which is what dotAll means).
const regexpPatchBanner = `
(function() {
var NativeRegExp = RegExp;
try { new NativeRegExp('.', 's'); } catch(e) {
RegExp = function RegExp(pattern, flags) {
if (typeof flags === 'string' && flags.indexOf('s') !== -1) {
flags = flags.replace(/s/g, '');
// Replace unescaped dots with [\\s\\S]
if (typeof pattern === 'string') {
var result = '', inClass = false;
for (var i = 0; i < pattern.length; i++) {
var ch = pattern[i];
if (ch === '\\\\' && i + 1 < pattern.length) {
result += ch + pattern[++i];
} else if (ch === '[') {
inClass = true; result += ch;
} else if (ch === ']') {
inClass = false; result += ch;
} else if (ch === '.' && !inClass) {
result += '[\\\\s\\\\S]';
} else {
result += ch;
}
}
pattern = result;
}
}
if (this instanceof RegExp) {
return new NativeRegExp(pattern, flags);
}
return NativeRegExp(pattern, flags);
};
RegExp.prototype = NativeRegExp.prototype;
Object.keys(NativeRegExp).forEach(function(k) { RegExp[k] = NativeRegExp[k]; });
}
})();
`;
const babelES5Options = {
presets: [
[
"@babel/preset-env",
{
targets: "ie 11",
modules: "commonjs",
},
],
],
};
module.exports = {
mode: 'production',
target: 'node',
entry: './src/pime.ts',
module: {
rules: [
{
test: /\.json$/,
resourceQuery: /raw/,
type: 'javascript/auto',
use: [
{
loader: path.resolve(__dirname, 'json-minifier-loader.js'),
},
],
},
{
test: /\.ts$/,
include: [path.resolve(__dirname, 'src')],
exclude: [
path.resolve(__dirname, 'src/index.ts'),
path.resolve(__dirname, 'src/chromeos_ime.ts'),
],
use: [
{
loader: 'babel-loader',
options: babelES5Options,
},
{
loader: 'ts-loader',
options: {
compilerOptions: {
target: 'es5',
module: 'commonjs',
downlevelIteration: true,
ignoreDeprecations: '6.0',
},
},
},
],
},
{
test: /\.mjs$/,
type: 'javascript/auto',
use: {
loader: 'babel-loader',
options: babelES5Options,
},
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'output/pime'),
libraryTarget: 'commonjs2',
environment: {
arrowFunction: false,
const: false,
destructuring: false,
dynamicImport: false,
forOf: false,
module: false,
optionalChaining: false,
templateLiteral: false,
methodShorthand: false,
},
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 5,
compress: {
ecma: 5,
},
format: {
ecma: 5,
},
},
}),
],
},
plugins: [
new webpack.BannerPlugin({
banner: regexpPatchBanner,
raw: true,
}),
],
};