wp-scripts only creates json and php files for blocks, missing index.js
-
I’m trying to use wp-scripts for my theme which includes blocks too. Yes, I know blocks are recommended to create as plugins. I however watched the Developer Hours: Modern WordPress development with the wp-scripts package where they go through how you can use it for themes as well.
I’m trying to copy some of the things I need from Justin Tadlock’s https://github.com/x3p0-dev/x3p0-ideas.
I have got it to work that both blocks and css are optimized by the building process. But one thing that is very odd is that only build.json and render.php are created for the blocks. Why could that be?
My package.json looks like this:
{ "name": "ptw", "version": "1.0.0", "description": "A theme", "main": "index.js", "dependencies": { "font-awesome": "^4.7.0", "jquery": "^3.7.1" }, "devDependencies": { "@wordpress/scripts": "^27.4.0", "path": "^0.12.7", "webpack-remove-empty-scripts": "^1.0.4" }, "scripts": { "start": "wp-scripts start", "build": "wp-scripts build" }, "author": "Peter W", "license": "ISC" }And my webpack.config.js looks like this:
// WordPress webpack config. const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); const { getWebpackEntryPoints } = require( '@wordpress/scripts/utils/config' ); // Plugins. const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' ); // Utilities. const path = require( 'path' ); // Add any a new entry point by extending the webpack config. module.exports = { ...defaultConfig, ...{ entry: { ...getWebpackEntryPoints(), 'css/site': path.resolve( process.cwd(), 'src/css', 'site.scss' ), 'css/learning-mode': path.resolve( process.cwd(), 'src/css', 'learning-mode.scss' ), }, plugins: [ // Include WP's plugin config. ...defaultConfig.plugins, // Removes the empty.jsfiles generated by webpack but // sets it after WP has generated its*.asset.phpfile. new RemoveEmptyScriptsPlugin( { stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS } ) ] } };Folder structure:
theme-root/ ├── build/ │ ├── blocks/ │ │ └── ptw-sensei-button/ │ │ ├── block.json │ │ └── render.php │ ├── css/ │ ├── fonts/ ├── includes/ ├── languages/ ├── src/ │ ├── blocks/ │ │ └── ptw-sensei-button/ │ │ ├── block.json │ │ ├── edit.js │ │ ├── editor.scss │ │ ├── index.js │ │ ├── render.php │ │ ├── style.scss │ │ └── view.js │ ├── css/ ├── vendor/ ├── composer.json ├── composer.lock ├── functions.php ├── package.json ├── package-lock.json ├── theme.json ├── webpack.config.js
The topic ‘wp-scripts only creates json and php files for blocks, missing index.js’ is closed to new replies.