Skip to content
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

@wordpress/scripts: path-based webpack entry points produce inconsist output file structure #32791

Closed
bosconian-dynamics opened this issue Jun 17, 2021 · 1 comment · Fixed by #32834
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts

Comments

@bosconian-dynamics
Copy link
Contributor

bosconian-dynamics commented Jun 17, 2021

Description

When extending @wordpress/scripts' webpack.config.js to add to entry using chunk/entry point names containing forward slashes, the style-{chunk name}.css files produced are output to a directory disparate from the rest of the assets and bundles built for that entrypoint.

Step-by-step reproduction instructions

  1. Override @wordpress/scripts' webpack.config.js file to add entrypoints with names including /:
const path = require( 'path' );
const config = require( '@wordpress/scripts/config/webpack.config.js' );

config.entry = {
  'blocks/foo/index': path.resolve( process.cwd(), 'src', 'blocks', 'foo', 'index.js' ),
  'frontend/accordion': path.resolve( process.cwd(), 'src', 'frontend', 'accordion.js' ),
};

module.exports = config;
  1. Execute wp-scripts build or wp-scripts start.

Expected behaviour

All built chunk bundles and assets are located in the path described by the entry-point name, relative to the output directory. An entry-point named 'blocks/foo/index' should result in src/blocks/foo/style.scss's built asset being output at build/blocks/foo/style-index.css:

image

Actual behaviour

The respective CSS files end up in a first-level directory separate from all other related assets. An entry-point named 'blocks/foo/index' results in src/blocks/foo/style.scss's built asset being output at build/style-blocks/foo/index.css:

image

@bosconian-dynamics bosconian-dynamics changed the title @wordpress/scripts: FixStyleWebpackPlugin produces output in incorrect locations for path-based chunk names @wordpress/scripts: style-{chunk name}.css files are output in incorrect locations when using path-based chunk names Jun 17, 2021
@bosconian-dynamics bosconian-dynamics changed the title @wordpress/scripts: style-{chunk name}.css files are output in incorrect locations when using path-based chunk names @wordpress/scripts: webpack splitChunks config incompatible with path-based entry names Jun 17, 2021
@bosconian-dynamics bosconian-dynamics changed the title @wordpress/scripts: webpack splitChunks config incompatible with path-based entry names @wordpress/scripts: path-based webpack entry points produce inconsist output file structure Jun 17, 2021
@bosconian-dynamics
Copy link
Contributor Author

bosconian-dynamics commented Jun 17, 2021

As it turns out, this is simply how Webpack v4's splitChunks automatic naming scheme works. It seems it could be overridden by specifying a splitChunks.name property, but the documentation recommends against doing so in production.

It would be nice if FixStyleWebpackPlugin could support such user-supplied splitChunks naming schemes.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jun 19, 2021
@skorasaurus skorasaurus added the [Tool] WP Scripts /packages/scripts label Jun 21, 2021
gziolo pushed a commit that referenced this issue Jun 22, 2021
…th-based chunk names (#32834)

Changes FixStyleWebpackPlugin's chunk name to file name resolution to
account for entrypoints containing forward slashes in their names,
resulting in the related `style-{chunk name}.css` files being output
within the path described by the chunk name rather than rooted to the
output directory.

Closes #32791.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts
Projects
None yet
2 participants