Skip to content

Commit 554efb4

Browse files
committed
feat(sass resolve paths) change webpack config to implement sassLoader's includePaths support
1 parent 3aa61d5 commit 554efb4

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

packages/angular-cli/blueprints/ng2/files/angular-cli.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"styles": [
2121
"styles.<%= styleExt %>"
2222
],
23+
<% if(styleExt==='sass') { %>"sassPaths": [],<% } %>
2324
"scripts": [],
2425
"environments": {
2526
"source": "environments/environment.ts",

packages/angular-cli/lib/config/schema.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface CliConfig {
2323
* Global styles to be included in the build.
2424
*/
2525
styles?: string[];
26+
/**
27+
* includePaths array for sass import.
28+
*/
29+
sassPaths?: string[];
2630
/**
2731
* Global scripts to be included in the build.
2832
*/

packages/angular-cli/lib/config/schema.json

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
},
6767
"additionalProperties": false
6868
},
69+
"sassPaths": {
70+
"description": "includePaths array for sass import.",
71+
"type": "array",
72+
"items": {
73+
"type": "string"
74+
},
75+
"additionalProperties": false
76+
},
6977
"scripts": {
7078
"description": "Global scripts to be included in the build.",
7179
"type": "array",

packages/angular-cli/models/webpack-build-development.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const path = require('path');
22

3+
import * as webpack from 'webpack';
4+
35
export const getWebpackDevConfigPartial = function(projectRoot: string, appConfig: any) {
6+
const appRoot = path.resolve(projectRoot, appConfig.root);
7+
const sass = appConfig.sassPaths
8+
? appConfig.sassPaths.map((includePath: string) => path.resolve(appRoot, includePath))
9+
: [];
410
return {
511
devtool: 'cheap-module-source-map',
612
output: {
@@ -9,6 +15,15 @@ export const getWebpackDevConfigPartial = function(projectRoot: string, appConfi
915
sourceMapFilename: '[name].map',
1016
chunkFilename: '[id].chunk.js'
1117
},
18+
plugins: [
19+
new webpack.LoaderOptionsPlugin({
20+
options: {
21+
sassLoader: {
22+
includePaths: sass
23+
}
24+
}
25+
})
26+
],
1227
node: {
1328
fs: 'empty',
1429
global: true,

packages/angular-cli/models/webpack-build-production.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ declare module 'webpack' {
1414
}
1515

1616
export const getWebpackProdConfigPartial = function(projectRoot: string, appConfig: any) {
17+
const appRoot = path.resolve(projectRoot, appConfig.root);
18+
const sass = appConfig.sassPaths
19+
? appConfig.sassPaths.map((includePath: string) => path.resolve(appRoot, includePath))
20+
: [];
1721
return {
1822
devtool: 'source-map',
1923
output: {
@@ -51,7 +55,10 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
5155
},
5256
postcss: [
5357
require('postcss-discard-comments')
54-
]
58+
],
59+
sassLoader: {
60+
includePaths: sass
61+
}
5562
}
5663
})
5764
],

0 commit comments

Comments
 (0)