Skip to content

Commit 203e1a4

Browse files
committedJun 25, 2021
refactor(@angular-devkit/build-angular): remove unused mime-types from style configuration
1 parent c666d0b commit 203e1a4

File tree

1 file changed

+70
-85
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+70
-85
lines changed
 

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

+70-85
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
238238
}
239239
}
240240

241+
const postCss = require('postcss');
242+
const postCssLoaderPath = require.resolve('postcss-loader');
243+
241244
const componentStyleLoaders: webpack.RuleSetUseItem[] = [
242245
{ loader: require.resolve('raw-loader') },
243246
{
244-
loader: require.resolve('postcss-loader'),
247+
loader: postCssLoaderPath,
245248
options: {
246-
implementation: require('postcss'),
249+
implementation: postCss,
247250
postcssOptions: postcssOptionsCreator(componentsSourceMap, false),
248251
},
249252
},
@@ -263,28 +266,65 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
263266
},
264267
},
265268
{
266-
loader: require.resolve('postcss-loader'),
269+
loader: postCssLoaderPath,
267270
options: {
268-
implementation: require('postcss'),
271+
implementation: postCss,
269272
postcssOptions: postcssOptionsCreator(false, buildOptions.extractCss),
270273
sourceMap: !!cssSourceMap,
271274
},
272275
},
273276
];
274277

278+
const extraMinimizers = [];
279+
if (buildOptions.optimization.styles.minify) {
280+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
281+
const minimizerOptions = {
282+
preset: [
283+
'default',
284+
{
285+
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
286+
svgo: false,
287+
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
288+
calc: false,
289+
// Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
290+
cssDeclarationSorter: false,
291+
},
292+
],
293+
};
294+
295+
const globalBundlesRegExp = new RegExp(
296+
`^(${Object.keys(entryPoints).join('|')})(\.[0-9a-f]{20})?.css$`,
297+
);
298+
299+
extraMinimizers.push(
300+
new CssMinimizerPlugin({
301+
// Component styles retain their original file name
302+
test: /\.(?:css|scss|sass|less|styl)$/,
303+
parallel: false,
304+
exclude: globalBundlesRegExp,
305+
minify: [CssMinimizerPlugin.cssnanoMinify],
306+
minimizerOptions,
307+
}),
308+
new CssMinimizerPlugin({
309+
test: /\.css$/,
310+
include: globalBundlesRegExp,
311+
parallel: maxWorkers,
312+
minify: [CssMinimizerPlugin.cssnanoMinify],
313+
minimizerOptions,
314+
}),
315+
);
316+
}
317+
275318
const styleLanguages: {
276319
extensions: string[];
277-
mimetype?: string;
278320
use: webpack.RuleSetUseItem[];
279321
}[] = [
280322
{
281323
extensions: ['css'],
282-
mimetype: 'text/css',
283324
use: [],
284325
},
285326
{
286327
extensions: ['scss'],
287-
mimetype: 'text/x-scss',
288328
use: [
289329
{
290330
loader: require.resolve('resolve-url-loader'),
@@ -314,7 +354,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
314354
},
315355
{
316356
extensions: ['sass'],
317-
mimetype: 'text/x-sass',
318357
use: [
319358
{
320359
loader: require.resolve('resolve-url-loader'),
@@ -328,6 +367,8 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
328367
implementation: sassImplementation,
329368
sourceMap: true,
330369
sassOptions: {
370+
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
371+
fiber: false,
331372
indentedSyntax: true,
332373
// bootstrap-sass requires a minimum precision of 8
333374
precision: 8,
@@ -343,7 +384,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
343384
},
344385
{
345386
extensions: ['less'],
346-
mimetype: 'text/x-less',
347387
use: [
348388
{
349389
loader: require.resolve('less-loader'),
@@ -360,7 +400,6 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
360400
},
361401
{
362402
extensions: ['styl'],
363-
mimetype: 'text/x-stylus',
364403
use: [
365404
{
366405
loader: require.resolve('stylus-loader'),
@@ -377,84 +416,30 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
377416
},
378417
];
379418

380-
const inlineLanguageRules: webpack.RuleSetRule[] = [];
381-
const fileLanguageRules: webpack.RuleSetRule[] = [];
382-
for (const language of styleLanguages) {
383-
if (language.mimetype) {
384-
// inline component styles use data URIs and processing is selected by mimetype
385-
inlineLanguageRules.push({
386-
mimetype: language.mimetype,
387-
use: [...componentStyleLoaders, ...language.use],
388-
});
389-
}
390-
391-
fileLanguageRules.push({
392-
test: new RegExp(`\\.(?:${language.extensions.join('|')})$`, 'i'),
393-
rules: [
394-
// Setup processing rules for global and component styles
395-
{
396-
oneOf: [
397-
// Component styles are all styles except defined global styles
398-
{
399-
exclude: globalStylePaths,
400-
use: componentStyleLoaders,
401-
},
402-
// Global styles are only defined global styles
403-
{
404-
include: globalStylePaths,
405-
use: globalStyleLoaders,
406-
},
407-
],
408-
},
409-
{ use: language.use },
410-
],
411-
});
412-
}
413-
414-
const extraMinimizers = [];
415-
if (buildOptions.optimization.styles.minify) {
416-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
417-
const minimizerOptions = {
418-
preset: [
419-
'default',
420-
{
421-
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
422-
svgo: false,
423-
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
424-
calc: false,
425-
// Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
426-
cssDeclarationSorter: false,
427-
},
428-
],
429-
};
430-
431-
const globalBundlesRegExp = new RegExp(
432-
`^(${Object.keys(entryPoints).join('|')})(\.[0-9a-f]{20})?.css$`,
433-
);
434-
435-
extraMinimizers.push(
436-
new CssMinimizerPlugin({
437-
// Component styles retain their original file name
438-
test: /\.(?:css|scss|sass|less|styl)$/,
439-
parallel: false,
440-
exclude: globalBundlesRegExp,
441-
minify: [CssMinimizerPlugin.cssnanoMinify],
442-
minimizerOptions,
443-
}),
444-
new CssMinimizerPlugin({
445-
test: /\.css$/,
446-
include: globalBundlesRegExp,
447-
parallel: maxWorkers,
448-
minify: [CssMinimizerPlugin.cssnanoMinify],
449-
minimizerOptions,
450-
}),
451-
);
452-
}
453-
454419
return {
455420
entry: entryPoints,
456421
module: {
457-
rules: [...fileLanguageRules, ...inlineLanguageRules],
422+
rules: styleLanguages.map(({ extensions, use }) => ({
423+
test: new RegExp(`\\.(?:${extensions.join('|')})$`, 'i'),
424+
rules: [
425+
// Setup processing rules for global and component styles
426+
{
427+
oneOf: [
428+
// Component styles are all styles except defined global styles
429+
{
430+
exclude: globalStylePaths,
431+
use: componentStyleLoaders,
432+
},
433+
// Global styles are only defined global styles
434+
{
435+
include: globalStylePaths,
436+
use: globalStyleLoaders,
437+
},
438+
],
439+
},
440+
{ use },
441+
],
442+
})),
458443
},
459444
optimization: {
460445
minimizer: extraMinimizers,

0 commit comments

Comments
 (0)
Please sign in to comment.