Skip to content

Commit 907eabd

Browse files
committed
fix(@angular/build): support ESM PostCSS plugins
This change updates the PostCSS plugin loader to support plugins distributed as ES modules. This allows modern PostCSS plugins authored in ESM to be used without import errors.
1 parent a0f45f9 commit 907eabd

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ export class StylesheetPluginFactory {
225225
postcssProcessor = postcss();
226226

227227
const postCssPluginRequire = createRequire(dirname(configPath) + '/');
228-
229228
for (const [pluginName, pluginOptions] of config.plugins) {
230-
const plugin = postCssPluginRequire(pluginName);
229+
const pluginMod = postCssPluginRequire(pluginName);
230+
const plugin = pluginMod.__esModule ? pluginMod['default'] : pluginMod;
231231
if (typeof plugin !== 'function' || plugin.postcss !== true) {
232232
throw new Error(`Attempted to load invalid Postcss plugin: "${pluginName}"`);
233233
}

packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export async function getStylesConfig(wco: WebpackConfigOptions): Promise<Config
8787
const postCssPluginRequire = createRequire(path.dirname(postcssConfig.configPath) + '/');
8888

8989
for (const [pluginName, pluginOptions] of postcssConfig.config.plugins) {
90-
const plugin = postCssPluginRequire(pluginName);
90+
const pluginMod = postCssPluginRequire(pluginName);
91+
const plugin = pluginMod.__esModule ? pluginMod['default'] : pluginMod;
9192
if (typeof plugin !== 'function' || plugin.postcss !== true) {
9293
throw new Error(`Attempted to load invalid Postcss plugin: "${pluginName}"`);
9394
}

0 commit comments

Comments
 (0)