mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
refactor(@angular-devkit/build-angular): minor CSS processing cleanup
This commit is contained in:
parent
1080357683
commit
1188e35b27
@ -9,8 +9,8 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Compiler } from 'webpack';
|
import { Compiler, compilation } from 'webpack';
|
||||||
import { RawSource, SourceMapSource } from 'webpack-sources';
|
import { RawSource, Source, SourceMapSource } from 'webpack-sources';
|
||||||
|
|
||||||
const CleanCSS = require('clean-css');
|
const CleanCSS = require('clean-css');
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ export class CleanCssWebpackPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apply(compiler: Compiler): void {
|
apply(compiler: Compiler): void {
|
||||||
hook(compiler, (compilation: any, chunks: Array<Chunk>) => {
|
hook(compiler, (compilation: compilation.Compilation, chunks: Array<Chunk>) => {
|
||||||
const cleancss = new CleanCSS({
|
const cleancss = new CleanCSS({
|
||||||
compatibility: 'ie9',
|
compatibility: 'ie9',
|
||||||
level: 2,
|
level: 2,
|
||||||
@ -80,7 +80,7 @@ export class CleanCssWebpackPlugin {
|
|||||||
const actions = files
|
const actions = files
|
||||||
.filter(file => this._options.test(file))
|
.filter(file => this._options.test(file))
|
||||||
.map(file => {
|
.map(file => {
|
||||||
const asset = compilation.assets[file];
|
const asset = compilation.assets[file] as Source;
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ export class CleanCssWebpackPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => cleancss.minify(content, map))
|
.then(() => map ? cleancss.minify(content, map) : cleancss.minify(content))
|
||||||
.then((output: any) => {
|
.then((output: any) => {
|
||||||
let hasWarnings = false;
|
let hasWarnings = false;
|
||||||
if (output.warnings && output.warnings.length > 0) {
|
if (output.warnings && output.warnings.length > 0) {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
export default function(content: string, map: object) {
|
export default function(content: string, map: object) {
|
||||||
const stringifiedContent = JSON.stringify(content);
|
const stringifiedContent = JSON.stringify(content);
|
||||||
const stringifiedMap = map && JSON.stringify(map);
|
const stringifiedMap = map ? JSON.stringify(map) : `''`;
|
||||||
|
|
||||||
return `module.exports = [[module.id, ${stringifiedContent}, '', ${stringifiedMap}]]`;
|
return `module.exports = [[module.id, ${stringifiedContent}, '', ${stringifiedMap}]]`;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user