mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 23:15:56 +08:00
fix(@angular-devkit/build-angular): Sass compilation in StackBlitz webcontainers
When `process.versions.webcontainer` is truthy it means that we are running in a StackBlitz webcontainer. `SassWorkerImplementation` uses `receiveMessageOnPort` Node.js `worker_thread` API to ensure sync behavior which is ~2x faster. However, it is non trivial to support this in a webcontainer and while slower we choose to use `dart-sass` which in Webpack uses the slower async path.
This commit is contained in:
parent
9e22d7a215
commit
ac66e400cd
@ -107,14 +107,16 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sassImplementation = new SassWorkerImplementation();
|
const sassImplementation = getSassImplementation();
|
||||||
extraPlugins.push({
|
if (sassImplementation instanceof SassWorkerImplementation) {
|
||||||
apply(compiler) {
|
extraPlugins.push({
|
||||||
compiler.hooks.shutdown.tap('sass-worker', () => {
|
apply(compiler) {
|
||||||
sassImplementation?.close();
|
compiler.hooks.shutdown.tap('sass-worker', () => {
|
||||||
});
|
sassImplementation?.close();
|
||||||
},
|
});
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const assetNameTemplate = assetNameTemplateFactory(hashFormat);
|
const assetNameTemplate = assetNameTemplateFactory(hashFormat);
|
||||||
|
|
||||||
@ -404,3 +406,14 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
|
|||||||
plugins: extraPlugins,
|
plugins: extraPlugins,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSassImplementation(): SassWorkerImplementation | typeof import('sass') {
|
||||||
|
const { webcontainer } = process.versions as unknown as Record<string, unknown>;
|
||||||
|
|
||||||
|
// When `webcontainer` is a truthy it means that we are running in a StackBlitz webcontainer.
|
||||||
|
// `SassWorkerImplementation` uses `receiveMessageOnPort` Node.js `worker_thread` API to ensure sync behavior which is ~2x faster.
|
||||||
|
// However, it is non trivial to support this in a webcontainer and while slower we choose to use `dart-sass`
|
||||||
|
// which in Webpack uses the slower async path.
|
||||||
|
// We should periodically check with StackBlitz folks (Mark Whitfeld / Dominic Elm) to determine if this workaround is still needed.
|
||||||
|
return webcontainer ? require('sass') : new SassWorkerImplementation();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user