Last active
November 5, 2021 23:45
-
-
Save ndunks/e9cb81b2861a2e905e5426b7d70fff9a to your computer and use it in GitHub Desktop.
Wordpress 5.8 Typescript Webpack Config - Gutenberg Blocks Development Environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "wordpress-typescript-sample", | |
"version": "1.0.0", | |
"main": "build/index.js", | |
"scripts": { | |
"start": "wp-scripts start" | |
}, | |
"dependencies": { | |
"@wordpress/blocks": "^11.1.2" | |
}, | |
"devDependencies": { | |
"@wordpress/scripts": "^19.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { join } = require("path"); | |
// Set default entry before loading wp webpack.config | |
process.env.WP_ENTRY = JSON.stringify({ index: join(__dirname, "src/index.tsx") }); | |
/** @type {import("webpack").Configuration} */ | |
const config = require("@wordpress/scripts/config/webpack.config"); | |
// Add Shortcut import path @/ as src/ | |
config.resolve = config.resolve || {}; | |
config.resolve.extensions = config.resolve.extensions || []; | |
config.resolve.extensions.push('.ts', '.tsx', '.js', '.jsx'); | |
config.resolve.alias = config.resolve.alias || {}; | |
config.resolve.alias['@'] = join(__dirname, 'src'); | |
// Add ts & tsx support | |
const babelLoader = config.module.rules.find( | |
v => v.test instanceof RegExp && v.test.test('.jsx') | |
); | |
if (babelLoader) { | |
babelLoader.test = /\.t|jsx?/ | |
} | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment