Skip to content

Commit 1acf498

Browse files
authored
[Website] Move dynamic extension files in assets/extensions directory (#2984)
## Motivation for the change, related issues Currently, when displaying the [assets-required-for-offline-mode.json file](https://playground.wordpress.net/assets-required-for-offline-mode.json), Intl dynamic extension files are present. This is due to dynamic importing and Vite builds automatically assigning these files in the assets directory. This pull request aims to move these files in the `assets/extensions` directory, an ignored directory for offline mode assets. ## Implementation details Added `chunkFileNames` and `assetFileNames` hooks in : - `packages/playground/website/vite.config.ts` - `packages/playground/remote/vite.config.ts` ## Testing Instructions (or ideally a Blueprint) run : ``` nx reset && nx run playground-website:build:standalone ``` You'll find the new file in `dist/packages/playground/website/assets-required-for-offline-mode.json`
1 parent dc1d12b commit 1acf498

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

packages/playground/remote/vite.config.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export default defineConfig(({ mode }) => {
4949
'CORS_PROXY_URL' in process.env
5050
? process.env['CORS_PROXY_URL']
5151
: mode === 'production'
52-
? 'https://wordpress-playground-cors-proxy.net/?'
53-
: 'http://127.0.0.1:5263/cors-proxy.php?';
52+
? 'https://wordpress-playground-cors-proxy.net/?'
53+
: 'http://127.0.0.1:5263/cors-proxy.php?';
5454

5555
plugins.push(
5656
virtualModule({
@@ -105,6 +105,29 @@ export default defineConfig(({ mode }) => {
105105
plugins: () => plugins,
106106
rollupOptions: {
107107
output: {
108+
assetFileNames: (chunkInfo) => {
109+
// Split Extensions or associated shared files into separate chunks
110+
// that will be placed in assets/extensions/ directory
111+
if (
112+
chunkInfo.names?.[0]?.endsWith('.so') ||
113+
chunkInfo.names?.[0]?.endsWith('.dat')
114+
) {
115+
return 'assets/extensions/[name]-[hash][extname]';
116+
}
117+
118+
return 'assets/[name]-[hash][extname]';
119+
},
120+
chunkFileNames: (chunkInfo: any) => {
121+
// Split Extensions or associated shared files into separate chunks
122+
// that will be placed in assets/extensions/ directory
123+
if (
124+
chunkInfo.facadeModuleId.endsWith('.so') ||
125+
chunkInfo.facadeModuleId.endsWith('.dat')
126+
) {
127+
return 'assets/extensions/[name]-[hash].js';
128+
}
129+
return 'assets/[name]-[hash].js';
130+
},
108131
// Ensure the service worker always has the same name
109132
entryFileNames: (chunkInfo: any) => {
110133
if (chunkInfo.name === 'service-worker') {
@@ -128,6 +151,20 @@ export default defineConfig(({ mode }) => {
128151
input: {
129152
wordpress: path('/remote.html'),
130153
},
154+
output: {
155+
assetFileNames: (chunkInfo) => {
156+
// Split Extensions or associated shared files into separate chunks
157+
// that will be placed in assets/extensions/ directory
158+
if (
159+
chunkInfo.names?.[0]?.endsWith('.so') ||
160+
chunkInfo.names?.[0]?.endsWith('.dat')
161+
) {
162+
return 'assets/extensions/[name]-[hash][extname]';
163+
}
164+
165+
return 'assets/[name]-[hash][extname]';
166+
},
167+
},
131168
},
132169
// Clean the output directory to make sure we include only the
133170
// latest WordPress builds.

0 commit comments

Comments
 (0)