You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-11Lines changed: 35 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,11 @@
2
2
3
3
Speed up your Webpack build with [esbuild](https://github.com/evanw/esbuild)! 🔥
4
4
5
+
[esbuild](https://github.com/evanw/esbuild) is a JavaScript bundler written in Go that supports blazing fast ESNext & TypeScript transpilation and JS minification.
5
6
6
-
[esbuild](https://github.com/evanw/esbuild) is written in Go, and supports blazing fast ESNext & TypeScript transpilation, and JS minification.
7
+
[esbuild-loader](https://github.com/privatenumber/esbuild-loader) lets you harness the speed of esbuild in your Webpack build by offering faster alternatives for transpilation (eg. babel-loader/ts-loader) and minification (eg. Terser)!
7
8
9
+
<sub>If you like this project, please star it & [follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub>
8
10
9
11
## 🚀 Install
10
12
@@ -31,8 +33,8 @@ In `webpack.config.js`:
31
33
+ test: /\.js$/,
32
34
+ loader: 'esbuild-loader',
33
35
+ options: {
34
-
+ target: 'es2015', // Syntax to compile to (see options below for possible values)
35
-
+ },
36
+
+ target: 'es2015' // Syntax to compile to (see options below for possible values)
37
+
+ }
36
38
+ },
37
39
38
40
...
@@ -55,26 +57,41 @@ In `webpack.config.js`:
55
57
rules: [
56
58
- {
57
59
- test: /\.tsx?$/,
58
-
- use: 'ts-loader',
60
+
- use: 'ts-loader'
59
61
- },
60
62
+ {
61
63
+ test: /\.tsx?$/,
62
64
+ loader: 'esbuild-loader',
63
65
+ options: {
64
66
+ loader: 'tsx', // Or 'ts' if you don't need tsx
65
-
+ target: 'es2015',
66
-
+ },
67
+
+ target: 'es2015'
68
+
+ }
67
69
+ },
68
70
69
71
...
70
-
],
72
+
]
71
73
},
72
74
plugins: [
73
75
+ new ESBuildPlugin()
74
76
]
75
77
}
76
78
```
77
79
80
+
#### Configuration
81
+
If you have a `tsconfig.json` file, you can pass it in via the `tsconfigRaw` option. Note, esbuild only supports [a subset of `tsconfig` options](https://github.com/evanw/esbuild/blob/master/lib/types.ts#L92) and does not do type checks.
82
+
83
+
```diff
84
+
{
85
+
test: /\.tsx?$/,
86
+
loader: 'esbuild-loader',
87
+
options: {
88
+
loader: 'tsx',
89
+
target: 'es2015',
90
+
+ tsconfigRaw: require('./tsconfig.json')
91
+
}
92
+
}
93
+
```
94
+
78
95
### Minification (eg. Terser)
79
96
You can replace JS minifiers like Terser or UglifyJs. Checkout the [benchmarks](https://github.com/privatenumber/minification-benchmarks) to see how much faster esbuild is.
80
97
@@ -92,8 +109,10 @@ In `webpack.config.js`:
92
109
+ optimization: {
93
110
+ minimize: true,
94
111
+ minimizer: [
95
-
+ new ESBuildMinifyPlugin()
96
-
+ ],
112
+
+ new ESBuildMinifyPlugin({
113
+
+ target: 'es2015' // Syntax to compile to (see options below for possible values)
114
+
+ })
115
+
+ ]
97
116
+ },
98
117
99
118
plugins: [
@@ -102,11 +121,15 @@ In `webpack.config.js`:
102
121
}
103
122
```
104
123
124
+
> _💁♀️ Protip: Use the minify plugin in-place of the loader to transpile your JS_
125
+
>
126
+
> The `target` option tells _esbuild_ that it can use newer JS syntax to perform better minification. If you're not using TypeScript or any syntax unsupported by Webpack, you can also leverage this as a transpilation step. It will be faster because there's less files to work on and will produce a smaller output because the polyfills will only be bundled once for the entire build instead of per file.
127
+
105
128
## ⚙️ Options
106
129
107
130
### Loader
108
131
The loader supports options from [esbuild](https://github.com/evanw/esbuild#command-line-usage).
0 commit comments