Closed oguilleux closed 9 months ago
Hi @oguilleux,
so you've just copied the source code from https://github.com/them-es/wordpress-blocks-starter to src
in the root of your theme, right?
This will interfere with the theme configuration because if you replace the root package.json
file, the theme frontend assets cannot be built anymore. A better approach would be to create a dedicated blocks
directory and move the source files from the Git repo there, as stated here.
In the end you'll need the webpack configuration for the theme i root and two different package.json
files:
{THEME_ROOT}/webpack.config.js
and {THEME_ROOT}/package.json
){THEME_ROOT}/blocks/package.json
). {THEME_ROOT}/blocks/index.php
needs to be referenced in your functions.php
as stated in the setup instructions.Does this answer your question?
PS: Thanks for the feedback btw. 😊
owh no that's exactly what I didn't want.
So there is no way with wordpress to have the @wordpress/scrips and a webpack config alongside that you can mess with ?
Don't know if it's a good practice but managed it like this :
const webpackConfig = require('@wordpress/scripts/config/webpack.config');
const { getWebpackEntryPoints } = require('@wordpress/scripts/utils/config');
module.exports = {
...webpackConfig,
//... code above
// context: path.resolve(__dirname, 'assets'), <--- commented
entry: {
...getWebpackEntryPoints(),
'js/main': path.resolve(__dirname, 'assets/main.js'),
'css/main': path.resolve(__dirname, 'assets/main.scss')
}
//... code below
}
Thanks for posting your solution.
If it's just relevant for the build task, another approach would be to combine the two commands in build
of the theme's /package.json
:
"build-blocks": "cd ./blocks/ && npm run build",
"build": "wp-scripts build && npm run build-blocks"
After executing $ npm run build
both tasks get executed with just one command.
I agree it just makes it a bit more verb-i-er.
BTW this solution didn't work for @wordpress/scripts > v26.19.0
for the moment and I edited my reply with my final solution. The bug can be followed here : https://github.com/WordPress/gutenberg/issues/58074
Also, this WordPress @wordpress/scripts tutorial helped me a lot : https://www.youtube.com/watch?v=UOiWgbK546Q
Hi thanks for your work, discovering the power of FSE !
I've added your wordpress block1 starter in a new
src
directory in the theme and just rannpm run start
but the block doesn't end up in thebuild
directory.When I delete the
webpack.config.js
the block ends up in build but all the other cool stuff like enjoying global js and scss don't work anymore.What am I missing out ?
Cheers