-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (77 loc) · 2.06 KB
/
webpack.config.js
File metadata and controls
79 lines (77 loc) · 2.06 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
const path = require("path")
const webpack = require("webpack")
const commonConfig = {
output: {
library: {
type: "umd",
name: "lolite",
},
globalObject: "this",
// This prevents Webpack from using arrow functions in the bundle wrapper
environment: {
arrowFunction: false,
const: false,
destructuring: false,
forOf: false,
module: false
}
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/, // Usually safe, but for ES3 you might need to compile some dependencies
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
// CoreJS 3 polyfills everything needed
useBuiltIns: "usage",
corejs: 3,
// Targeting a specific old engine or just generic ES3
targets: {
ie: "6"
},
// Ensures Babel doesn't use ES6 imports/exports in its own output
modules: "commonjs"
}
]
],
// This is the secret sauce for ES3: it renames properties like .catch() to ["catch"]()
plugins: [
"@babel/plugin-transform-member-expression-literals",
"@babel/plugin-transform-property-literals"
]
}
}
}
]
}
}
module.exports = [
// 1. Standard Node Build
{
...commonConfig,
entry: "./src/lolite.js",
mode: "development",
target: ["web", "es3"], // Explicitly tell Webpack to target ES3
devtool: "source-map",
externalsPresets: { node: true },
externals: [
({ request }, callback) => {
if (!/^\./.test(request) && !path.isAbsolute(request)) {
return callback(null, "commonjs " + request)
}
callback()
},
],
output: {
...commonConfig.output,
path: path.resolve(__dirname, "dist"),
filename: "lolite.js",
},
}
]