Skip to content

Commit bb99130

Browse files
committed
feat: add option to disable handling wordpress externals
It becomes useful when using wpackio webpack config in external tools like styleguidist.
1 parent 69330b6 commit bb99130

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

β€Žpackages/scripts/src/config/CreateWebpackConfig.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export class CreateWebpackConfig {
172172
tsBabelOverride,
173173
tsBabelPresetOptions,
174174
useReactJsxRuntime,
175+
disableWordPressExternals,
175176
} = this.projectConfig;
176177
const { host, port } = this.serverConfig;
177178
const helper: WebpackConfigHelper = new WebpackConfigHelper(
@@ -201,6 +202,7 @@ export class CreateWebpackConfig {
201202
tsBabelOverride,
202203
tsBabelPresetOptions,
203204
useReactJsxRuntime,
205+
disableWordPressExternals,
204206
},
205207
this.cwd,
206208
this.isDev

β€Žpackages/scripts/src/config/WebpackConfigHelper.tsβ€Ž

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export interface WebpackConfigHelperConfig {
5959
publicPathUrl: string;
6060
errorOverlay: ProjectConfig['errorOverlay'];
6161
externals: ProjectConfig['externals'];
62+
// whether or not to disable wordpress external scripts handling
63+
disableWordPressExternals?: boolean;
6264
}
6365

6466
interface CommonWebpackConfig {
@@ -325,12 +327,14 @@ export class WebpackConfigHelper {
325327
}
326328

327329
// Add wordpress dependency extract plugin
328-
plugins.push(
329-
new DependencyExtractionWebpackPlugin({
330-
gutenbergOptimized: this.file.optimizeForGutenberg ?? false,
331-
appDir: this.appDir,
332-
})
333-
);
330+
if (this.config.disableWordPressExternals !== true) {
331+
plugins.push(
332+
new DependencyExtractionWebpackPlugin({
333+
gutenbergOptimized: this.file.optimizeForGutenberg ?? false,
334+
appDir: this.appDir,
335+
})
336+
);
337+
}
334338

335339
// Add development specific plugins
336340
if (this.isDev) {

β€Žpackages/scripts/src/config/project.config.default.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export interface ProjectConfig {
100100
packageFiles: string[];
101101
packageDirPath: string;
102102
zlibLevel?: number;
103+
// whether or not to disable wordpress external scripts handling
104+
disableWordPressExternals?: boolean;
103105
}
104106

105107
/**
@@ -187,4 +189,6 @@ export const projectConfigDefault: ProjectConfig = {
187189
packageDirPath: 'package',
188190
// Level of zlib compression, when creating archive
189191
zlibLevel: 4,
192+
// whether or not to disable wordpress external scripts handling
193+
disableWordPressExternals: false,
190194
};

β€Žpackages/scripts/templates/wpackio.project.js.hbsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ module.exports = {
9696
],
9797
// Path to package directory, relative to the root
9898
packageDirPath: 'package',
99+
// whether or not to disable wordpress external scripts handling
100+
disableWordPressExternals: false,
99101
};

β€Žsite/docs/apis/project-configuration.mdβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,10 @@ The generated package file will also have name like `<slug>.zip`.
428428
## zlibLevel (`number`)
429429

430430
The level of zlib compression to use when creating the zip.
431+
432+
## disableWordPressExternals (`boolean`)
433+
434+
Whether or not to disable wordpress external scripts handling. If this option
435+
is set to true, then no `@wordpress` name-spaced dependencies will be extracted
436+
as an external. Also the dependencies json file which the PHP library depends on
437+
(but will not fail if is not present) will not be created.

0 commit comments

Comments
Β (0)