-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
49 lines (45 loc) · 1.46 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
// This comes from https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/config/webpack.config.js
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
// Modified config
module.exports = {
// Since whatever object we export from this file will *replace* the default config, we need to
// make sure to constantly pull in the default values from WordPress's config file
...defaultConfig,
// Point to your main file, wherever it is, which should now be TS
entry: `./src/index.tsx`,
// We need to add a new rule to process `.ts` and `.tsx` files with `ts-loader
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
// Notice that this regex matches both `.ts` and `.tsx`
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
// You can specify any custom config
configFile: "tsconfig.json",
// See note under "issues" for details
// Speeds up by skipping type-checking. You can still use TSC for that.
transpileOnly: true,
},
},
],
},
],
},
// This merges the extensions setting with whatever WP has in their config, but also adds TS
// extensions, and puts them first, to indicate preferred resolving over .js files
// @see https://webpack.js.org/configuration/resolve/
resolve: {
extensions: [
".ts",
".tsx",
...(defaultConfig.resolve
? defaultConfig.resolve.extensions || [".js", ".jsx"]
: []),
],
},
};