minor: Improve styleResources to handle multiple pre-provcessors

This commit is contained in:
Sébastien Chopin 2018-01-08 10:37:10 +01:00
parent 38d38d8d39
commit eceb92502b
4 changed files with 9 additions and 9 deletions

View File

@ -20,10 +20,13 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
// style-resources-loader // style-resources-loader
// https://github.com/yenshih/style-resources-loader // https://github.com/yenshih/style-resources-loader
if (this.options.build.styleResources) { if (this.options.build.styleResources[ext]) {
const patterns = Array.isArray(this.options.build.styleResources[ext]) ? this.options.build.styleResources[ext] : [ this.options.build.styleResources[ext] ]
const options = Object.assign({}, (this.options.build.styleResources.options || {}), { patterns })
loaders.push({ loaders.push({
loader: 'style-resources-loader', loader: 'style-resources-loader',
options: Object.assign({ sourceMap }, this.options.build.styleResources) options
}) })
} }
@ -32,6 +35,7 @@ module.exports = function styleLoader(ext, loaders = [], isVueLoader = false) {
// https://github.com/postcss/postcss-loader // https://github.com/postcss/postcss-loader
if (!isVueLoader) { if (!isVueLoader) {
const _postcssConfig = postcssConfig.call(this) const _postcssConfig = postcssConfig.call(this)
if (_postcssConfig) { if (_postcssConfig) {
loaders.unshift({ loaders.unshift({
loader: 'postcss-loader', loader: 'postcss-loader',

View File

@ -170,6 +170,7 @@ Options.defaults = {
app: 'app.[chunkhash].js', app: 'app.[chunkhash].js',
chunk: '[name].[chunkhash].js' chunk: '[name].[chunkhash].js'
}, },
styleResources: {},
vendor: [], vendor: [],
plugins: [], plugins: [],
babel: {}, babel: {},

View File

@ -50,9 +50,7 @@ module.exports = {
generateStatsFile: true generateStatsFile: true
}, },
styleResources: { styleResources: {
patterns: [ scss: '~/assets/pre-process.scss'
'~/assets/pre-process.scss'
]
}, },
babel: { babel: {
presets({ isServer }) { presets({ isServer }) {

View File

@ -187,10 +187,7 @@ test('Check build.styleResources for style-resources-loader', async t => {
const loader = loaders.find(l => l.loader === 'style-resources-loader') const loader = loaders.find(l => l.loader === 'style-resources-loader')
t.is(typeof loader, 'object') t.is(typeof loader, 'object')
t.deepEqual(loader.options, { t.deepEqual(loader.options, {
sourceMap: false, patterns: ['~/assets/pre-process.scss']
patterns: [
'~/assets/pre-process.scss'
]
}) })
}) })