I am using Webpack from @wordpress/scripts in my WordPress Child theme. By default, the output files are generated inside the build
folder. However, I would like to change the output path. I would like to separate my compiled js and CSS files into different subfolders inside the build folder, e.g. build/css
and build/js
. How can I do this? This is the Webpack configuration I am using:
webpack.config.js
/**
* External Dependencies
*/
const path = require( 'path' );
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
/**
* WordPress Dependencies
*/
const defaultConfig = require( '@wordpress/scripts/config/webpack.config.js' );
module.exports = {
...defaultConfig,
...{
entry: {
main: path.resolve( process.cwd(), 'src/scss', 'main.scss' ),
app: path.resolve( process.cwd(), 'src/js', 'app.js' ),
},
},
plugins: [ new FixStyleOnlyEntriesPlugin(), new MiniCssExtractPlugin() ],
};