Skip to content

Commit 4408211

Browse files
committed
feat: allow configuring scss options separately from sass
closes vuejs#4116
1 parent d787448 commit 4408211

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

packages/@vue/cli-service/__tests__/css.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ test('css.loaderOptions', () => {
198198
expect(findOptions(config, 'sass', 'sass')).toMatchObject({ data, indentedSyntax: true, sourceMap: false })
199199
})
200200

201+
test('scss loaderOptions', () => {
202+
const sassData = '$env: production'
203+
const scssData = '$env: production;'
204+
205+
const config = genConfig({
206+
vue: {
207+
css: {
208+
loaderOptions: {
209+
sass: {
210+
sassData
211+
},
212+
scss: {
213+
scssData
214+
}
215+
}
216+
}
217+
}
218+
})
219+
220+
expect(findOptions(config, 'scss', 'sass')).toMatchObject({ scssData, sourceMap: false })
221+
expect(findOptions(config, 'sass', 'sass')).toMatchObject({ sassData, indentedSyntax: true, sourceMap: false })
222+
})
223+
201224
test('should use dart sass implementation whenever possible', () => {
202225
const config = genConfig()
203226
expect(findOptions(config, 'scss', 'sass')).toMatchObject({ fiber: require('fibers'), implementation: require('sass') })

packages/@vue/cli-service/lib/config/css.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ module.exports = (api, rootOptions) => {
162162

163163
createCSSRule('css', /\.css$/)
164164
createCSSRule('postcss', /\.p(ost)?css$/)
165-
createCSSRule('scss', /\.scss$/, 'sass-loader', Object.assign(defaultSassLoaderOptions, loaderOptions.sass))
166-
createCSSRule('sass', /\.sass$/, 'sass-loader', Object.assign(defaultSassLoaderOptions, {
167-
indentedSyntax: true
168-
}, loaderOptions.sass))
165+
createCSSRule('scss', /\.scss$/, 'sass-loader', Object.assign(
166+
defaultSassLoaderOptions,
167+
loaderOptions.scss || loaderOptions.sass
168+
))
169+
createCSSRule('sass', /\.sass$/, 'sass-loader', Object.assign(
170+
defaultSassLoaderOptions,
171+
{
172+
indentedSyntax: true
173+
},
174+
loaderOptions.sass
175+
))
169176
createCSSRule('less', /\.less$/, 'less-loader', loaderOptions.less)
170177
createCSSRule('stylus', /\.styl(us)?$/, 'stylus-loader', Object.assign({
171178
preferPathResolver: 'webpack'

packages/@vue/cli-service/lib/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const schema = createSchema(joi => joi.object({
4040
loaderOptions: joi.object({
4141
css: joi.object(),
4242
sass: joi.object(),
43+
scss: joi.object(),
4344
less: joi.object(),
4445
stylus: joi.object(),
4546
postcss: joi.object()

0 commit comments

Comments
 (0)