-
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: Allow changing file entry and output of build scripts #14891
Comments
@helgatheviking - how about we make it an option for the /cc @nosolosw |
@gziolo I'm all for whatever way makes it easy for future me. So an option (documented of course!) is perfect. |
I can take a look at this! |
FWIW, what we're doing in I'd like to modestly suggest changing (I can give this a stab.) |
As it stands today, Related docs https://developer.wordpress.org/block-editor/packages/packages-scripts/#advanced-usage That said, we offer a webpack config today and if there are ways to improve the implementation, we're open to it. |
I think https://github.com/WordPress/gutenberg/blob/master/packages/scripts/utils/config.js#L25-L32 https://github.com/WordPress/gutenberg/blob/master/packages/scripts/scripts/start.js#L14 @nosolosw should give you more details about it. Otherwise, you might be able to pass all params webpack supports as well and they should just work. The reason we don't cover it in docs was explained by @youknowriad in the previous comments. |
I think the implementation could be simplified by essentially replacing As a side effect, it will allow passing Webpack args like output path and specifying entry points to the command, which I thought was the consensus of this issue, e.g.
While adding some flexibility here, the tool would still be usable as before, i.e. I think it wouldn't become less of an easy-to-use tool for plugin and theme authors. It would also be a step towards convergence with Anyway, let me know what you think about this suggestion. |
What I really care about is the API. I think the ideal API is something like:
I feel like if we allow any webpack config, it's harping the CLI API a little bit. |
I think that this format (unnamed entry points) is supported by Webpack OOTB, meaning we'd get it for free as well if we just pass arguments right through to Webpack.
Hmm, why do you think so? I guess the vast majority of users would continue to use the command without any args; some would maybe specify entry points and output path; and only very few would tweak more advanced settings. (Some of this might be philosophical -- personally, I've concluded that if what I'm doing is essentially running Webpack, I might as well expose its API. Saves me from needing to add extra CLI args as they're requested, and from maintaining layers of extra tooling that I wrap around it.) |
I agree that it's mainly a philosophical problem:
|
Yeah, was about to suggest whitelisting. Still might require a bit of parsing to be able to e.g. recognize different entry point formats (and thus a fatter wrapper than I'd ideally like, but oh well 😅) |
@ockham would you mind sharing a quick proof of concept? It should be easier to discuss based on code than trying to imagine the subtle differences you are proposing. It feels like it’s not that far from what @youknowriad explains on the higher level. The goal is to have reasonable defaults for all projects which operate in WordPress ecosystem with all possible optimizations when developing blocks. |
@gziolo Happy to share a PoC, yep! BTW, turns out that |
As a consequence, my PoC is essentially a FWIW, diff --git a/packages/scripts/scripts/build.js b/packages/scripts/scripts/build.js
index 2c3b9318a..d3e1925e8 100644
--- a/packages/scripts/scripts/build.js
+++ b/packages/scripts/scripts/build.js
@@ -1,18 +1,7 @@
-/**
- * External dependencies
- */
-const { sync: spawn } = require( 'cross-spawn' );
-const { sync: resolveBin } = require( 'resolve-bin' );
-
/**
* Internal dependencies
*/
const { getWebpackArgs } = require( '../utils' );
-process.env.NODE_ENV = process.env.NODE_ENV || 'production';
-const { status } = spawn(
- resolveBin( 'webpack' ),
- getWebpackArgs(),
- { stdio: 'inherit' }
-);
-process.exit( status );
+process.argv = [ 'dummy', 'arg', ...getWebpackArgs() ]; // Need to 'pad' two leading args for Webpack to remove
+require( 'webpack-cli' ); |
|
I proposed support for multiple entry points in #15982. I also discovered that it works out of the box as of today with the following command: $ npx wp-scripts build entry-one=./entry-one.js entry-two=./entry-two.js --output-path=dist There is no need to override the default webpack config. |
The Webpack config is no longer needed as of WordPress/gutenberg#14891.
Is your feature request related to a problem? Please describe.
I am using the WordPress build scripts to fasttrack my ability to work with Gutenberg. I'm very new to the ideal of webpack, but in my existing plugins using the default
src
andbuild
file location and naming conventions is not ideal.The readme does explain that you can extend the webpack config. But if you're very new, that example doesn't help with the file location.
Describe the solution you'd like
Include an example of changing the file name/locations for input and output. I am obviously biased here, but it strikes me as the most likely need for anyone just starting.
Describe alternatives you've considered
I did eventually figure this out, so for anyone else who needs it, saving the following to your project folders root as
webpack.config.js
seems to do the trick. This changes the input file to/js/src/index.js
and the output to/js/dist/index.js
The text was updated successfully, but these errors were encountered: