When using @wordpress/scripts to create a React app for WordPress, the default configuration to build the app is via running one of the following two scripts wp-scripts build
or wp-scripts start
(both run from within package.json). Both scripts will take the code from the src directory and build it into the build directory.
I would like to change the destination directory; for example, I would like the result to be in dist/app instead of build. I found an option to change the source directory; the option is --webpack-src-dir
(I have not used it, but I think with a little bit of tinkering, I will find out how), however I could not find a way of changing the destination directory. Is this possible?
Thanks.
PS: This is the first time using React with WordPress, so apologies about the simple question.
--output-path
can be used for that - from the documentation,"build:custom": "wp-scripts build entry-one.js entry-two.js --output-path=custom"
and "npm run build:custom
- builds the code for production with two entry points and a custom output directory. Paths for custom entry points are relative to the project root".entry-one.js entry-two.js
was just an example, and I'm pretty sure it will work even for a single entry,wp-scripts build foo.js --output-path=custom
- I already tried it long ago. It's just I would only write an answer after testing it again. So if it works for you, then just write your own answer :)