-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripts: Enhance the way entry points are detected in projects consisting of blocks and editor plugins #55936
Comments
If I run |
Yes, this is the order of how entry points are created for JavaScript files using webpack: gutenberg/packages/scripts/utils/config.js Lines 181 to 191 in e0c80ab
When That's said. We are open for iteration based on the feedback received as we plan to expand the application of the build tools outside of blocks, but also to make them helpful when building JS plugins and block themes. |
@gziolo Thanks for the explanation. I hope you can add a way to build both blocks and plugins found in the same directory. It would be very useful for those of us coding for clients. |
Hi, |
The issue is still not resolved. |
I was thinking about it again. We added, at some point, automatic detection of the gutenberg/packages/scripts/utils/config.js Lines 300 to 302 in 05b78e0
If we remove that condition, we could combine the entry points detected for blocks with |
@bacoords and @aurooba, I remember you discussing in the viewSource podcast the need to improve |
@gziolo Thanks for the tag! So from what I recall, our issues mostly have to do with multiple entry points. Basically every entry point is treated as a block, meaning if you had a theme and wanted to also use I believe that was the main issue, but will let @aurooba add or correct me where I'm wrong. |
I wanted to add another issue (or need for documentation) that seems to be related to entry points. When building a block and pulling in external CSS dependencies or scss partials into block stylesheets:
Meaning the only way to import CSS from a dependency into a frontend stylesheet for a block is to import it in your |
You can have multiple entry points using const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
index: './src/index.js',
},
}; This would build all the usual build tools for |
I added your |
@jdamner, this works great, thank you. Do you know if this is compatible with HMR using
|
@xsonic I'm not sure, I don't use
|
Trying this out but getting
webpack.config.js // WordPress webpack config.
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
// Plugins.
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
// Utilities.
const path = require('path');
// Add any new entry points by extending the webpack config.
module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
'theme-js': path.resolve(process.cwd(), 'src/js', 'index.js'),
'theme-css': path.resolve(process.cwd(), 'src/css', 'style.scss'),
},
}; |
@james0r this line is calling
Will you try replacing it with this:
|
When using defaultConfig.entry I get
|
@james0r What version of |
I am fetching the same error with this code
The version I am using is: 27.9.0 |
I just figured out that I'm only having the I also found this starter theme which is a great resource https://github.com/bacoords/block-theme |
I ran into the same problem. With the added flag the default config becomes an array. You can make the custom Webpack config working with the following:
|
@james0r troychaplin published a multi-block, with additional non-block scripts, in one plugin solution: https://github.com/wptrainingteam/building-multi-block-plugin/tree/DontCombineBlockScripts. Not tested with |
@daotw I just tested and that repo you shared does not fix the issue of the wrong Webpack config arising when using the |
@daotw and @ghostintranslation you can also use the following. Below is an example of a block I am creating using the interactivity api along with an "admin" slot fill for a panel on multiple post types
Then from there can use default define or expand the config
|
PR with the required changes to improve handling for projects containing editor plugins or theme styles is ready for review: |
Adding the experimental module has this issue with webpack.config:
|
Description
I regularly use
@wordpress/scripts
for building both blocks and non-block components. Recently, I started working in a new plugin that registers both some blocks and non-block components that add additional panels using theregisterPlugin()
function. This is the structure of my/src
directory:This is the content of the root
index.js
file:Until now, I can't remember having any problems with the build script in
@wordpress/scripts
: It built both the blocks and the components found in the/src
directory. But now, for some reason, it just builds the blocks, ignoring the components completely. The thing is that if I remove the/blocks
directory then the components are built with no issues.Has anything changed in
@wordpress/scripts
recently?Step-by-step reproduction instructions
Create a
/src
directory with blocks and non-block componentsRun
npm build
The script ignores the non-block components
Screenshots, screen recording, code snippet
No response
Environment info
WP 6.3
No Gutenberg plugin
Windows 10
NPM 10.2.0
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: