Skip to content

Commit f4aedc1

Browse files
clydinhansl
authored andcommitted
refactor(@angular-devkit/build-webpack): use mini-css-extract-plugin
1 parent b1f446e commit f4aedc1

File tree

7 files changed

+43
-59
lines changed

7 files changed

+43
-59
lines changed

package-lock.json

Lines changed: 13 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@
8585
"chalk": "~2.2.2",
8686
"chokidar": "^1.7.0",
8787
"circular-dependency-plugin": "^4.4.0",
88-
"clean-css": "^4.1.9",
88+
"clean-css": "^4.1.11",
8989
"codelyzer": "^4.0.2",
9090
"common-tags": "^1.5.1",
9191
"conventional-changelog": "^1.1.0",
9292
"copy-webpack-plugin": "^4.5.0",
9393
"express": "^4.16.2",
94-
"extract-text-webpack-plugin": "~4.0.0-beta.0",
9594
"file-loader": "^1.1.11",
9695
"font-awesome": "^4.7.0",
9796
"glob": "^7.0.3",
@@ -115,6 +114,7 @@
115114
"lodash": "^4.17.4",
116115
"material-design-icons": "^3.0.1",
117116
"memory-fs": "^0.4.1",
117+
"mini-css-extract-plugin": "~0.2.0",
118118
"minimatch": "^3.0.4",
119119
"minimist": "^1.2.0",
120120
"node-sass": "^4.7.2",

packages/angular_devkit/build_webpack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
"cache-loader": "^1.2.2",
1616
"chalk": "~2.2.2",
1717
"circular-dependency-plugin": "^4.4.0",
18-
"clean-css": "^4.1.9",
18+
"clean-css": "^4.1.11",
1919
"common-tags": "^1.5.1",
2020
"copy-webpack-plugin": "^4.5.0",
21-
"extract-text-webpack-plugin": "~4.0.0-beta.0",
2221
"file-loader": "^1.1.11",
2322
"glob": "^7.0.3",
2423
"html-webpack-plugin": "^3.0.6",
@@ -28,6 +27,7 @@
2827
"license-webpack-plugin": "^1.2.3",
2928
"lodash": "^4.17.4",
3029
"memory-fs": "^0.4.1",
30+
"mini-css-extract-plugin": "~0.2.0",
3131
"minimatch": "^3.0.4",
3232
"node-sass": "^4.7.2",
3333
"parse5": "^4.0.0",

packages/angular_devkit/build_webpack/src/angular-cli-files/models/webpack-configs/styles.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { SuppressExtractedTextChunksWebpackPlugin } from '../../plugins/webpack'
77
import { extraEntryParser, getOutputHashFormat } from './utils';
88
import { WebpackConfigOptions } from '../build-options';
99
import { findUp } from '../../utilities/find-up';
10+
import { RawCssLoader } from '../../plugins/webpack';
1011

1112
const postcssUrl = require('postcss-url');
1213
const autoprefixer = require('autoprefixer');
13-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
14+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1415
const postcssImports = require('postcss-import');
1516
const PostcssCliResources = require('../../plugins/webpack').PostcssCliResources;
1617

@@ -210,14 +211,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
210211
}
211212
];
212213

213-
const commonLoaders: webpack.Loader[] = [
214-
{ loader: 'raw-loader' },
215-
];
216-
217214
// load component css as raw strings
218215
const rules: webpack.Rule[] = baseRules.map(({ test, use }) => ({
219216
exclude: globalStylePaths, test, use: [
220-
...commonLoaders,
217+
{ loader: 'raw-loader' },
221218
{
222219
loader: 'postcss-loader',
223220
options: {
@@ -235,7 +232,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
235232
rules.push(...baseRules.map(({ test, use }) => {
236233
const extractTextPlugin = {
237234
use: [
238-
...commonLoaders,
235+
{ loader: RawCssLoader },
239236
{
240237
loader: 'postcss-loader',
241238
options: {
@@ -252,8 +249,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
252249
const ret: any = {
253250
include: globalStylePaths,
254251
test,
255-
use: buildOptions.extractCss ? ExtractTextPlugin.extract(extractTextPlugin)
256-
: ['style-loader', ...extractTextPlugin.use]
252+
use: [
253+
buildOptions.extractCss ? MiniCssExtractPlugin.loader : 'style-loader',
254+
...extractTextPlugin.use,
255+
]
257256
};
258257
// Save the original options as arguments for eject.
259258
// if (buildOptions.extractCss) {
@@ -266,7 +265,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
266265
if (buildOptions.extractCss) {
267266
// extract global css from js files into own css file
268267
extraPlugins.push(
269-
new ExtractTextPlugin({ filename: `[name]${hashFormat.extract}.css` }));
268+
new MiniCssExtractPlugin({ filename: `[name]${hashFormat.script}.css` }));
270269
// suppress empty .js files in css only entry points
271270
extraPlugins.push(new SuppressExtractedTextChunksWebpackPlugin());
272271
}

packages/angular_devkit/build_webpack/src/angular-cli-files/plugins/cleancss-webpack-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class CleanCssWebpackPlugin {
8787

8888
let content: string;
8989
let map: any;
90-
if (asset.sourceAndMap) {
90+
if (this._options.sourceMap && asset.sourceAndMap) {
9191
const sourceAndMap = asset.sourceAndMap();
9292
content = sourceAndMap.source;
9393
map = sourceAndMap.map;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export default function(content: string, map: object) {
10+
const stringifiedContent = JSON.stringify(content);
11+
const stringifiedMap = map && JSON.stringify(map);
12+
13+
return `module.exports = [[module.id, ${stringifiedContent}, '', ${stringifiedMap}]]`;
14+
}

packages/angular_devkit/build_webpack/src/angular-cli-files/plugins/webpack.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export {
1212
PostcssCliResourcesOptions,
1313
} from './postcss-cli-resources';
1414

15+
import { join } from 'path';
16+
export const RawCssLoader = require.resolve(join(__dirname, 'raw-css-loader'));

0 commit comments

Comments
 (0)