diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index a8cefd8452a3ec..6f8a36b0b81fa7 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -114,6 +114,7 @@ build_files=$( build/block-library/blocks/*.php \ build/block-library/blocks/*/block.json \ build/block-library/blocks/*/*.css \ + build/block-library/blocks/*/*.js \ build/edit-widgets/blocks/*/block.json \ ) diff --git a/webpack.config.js b/webpack.config.js index e319703d77d5a8..4915d8e0b385f1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -135,16 +135,19 @@ module.exports = { entry: createEntrypoints(), output: { devtoolNamespace: 'wp', - filename: ( data ) => { - const { chunk } = data; + filename: ( pathData ) => { + const { chunk } = pathData; const { entryModule } = chunk; - const { rawRequest } = entryModule; + const { rawRequest, rootModule } = entryModule; - /* - * If the file being built is a Core Block's frontend file, - * we build it in the block's directory. - */ - if ( rawRequest && rawRequest.includes( '/frontend.js' ) ) { + // When processing ESM files, the requested path + // is defined in `entryModule.rootModule.rawRequest`, instead of + // being present in `entryModule.rawRequest`. + // In the context of frontend files, they would be processed + // as ESM if they use `import` or `export` within it. + const request = rootModule?.rawRequest || rawRequest; + + if ( request.includes( '/frontend.js' ) ) { return `./build/block-library/blocks/[name]/frontend.js`; }