Skip to content

Commit 1666b8e

Browse files
Fix style loader
1 parent e8a79d4 commit 1666b8e

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

template/utils.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin')
33

44
exports.cssLoaders = function (options) {
55
options = options || {}
6+
var isProduction = process.env.NODE_ENV === 'production'
7+
var cssLoader = 'css' + (isProduction ? '?minimize' : '')
8+
69
// generate loader string to be used with extract text plugin
7-
function generateLoaders (loaders) {
10+
function generateLoaders (loader) {
11+
var loaders = [cssLoader]
12+
if (loader) loaders.push(loader)
813
var sourceLoader = loaders.map(function (loader) {
914
var extraParamChar
1015
if (/\?/.test(loader)) {
@@ -15,24 +20,29 @@ exports.cssLoaders = function (options) {
1520
extraParamChar = '?'
1621
}
1722
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
18-
}).join('!')
23+
})
1924

25+
// Extract CSS when that option is specified
26+
// (which is the case during production build)
2027
if (options.extract) {
21-
return ExtractTextPlugin.extract({fallback: 'vue-style-loader', use: sourceLoader})
28+
return ExtractTextPlugin.extract({
29+
use: sourceLoader,
30+
fallback: 'vue-style-loader'
31+
})
2232
} else {
23-
return ['vue-style-loader', sourceLoader].join('!')
33+
return ['vue-style-loader'].concat(sourceLoader)
2434
}
2535
}
2636

27-
// http://vuejs.github.io/vue-loader/configurations/extract-css.html
37+
// http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
2838
return {
29-
css: generateLoaders(['css']),
30-
postcss: generateLoaders(['css']),
31-
less: generateLoaders(['css', 'less']),
32-
sass: generateLoaders(['css', 'sass?indentedSyntax']),
33-
scss: generateLoaders(['css', 'sass']),
34-
stylus: generateLoaders(['css', 'stylus']),
35-
styl: generateLoaders(['css', 'stylus'])
39+
css: generateLoaders(),
40+
postcss: generateLoaders(),
41+
less: generateLoaders('less'),
42+
sass: generateLoaders('sass?indentedSyntax'),
43+
scss: generateLoaders('sass'),
44+
stylus: generateLoaders('stylus'),
45+
styl: generateLoaders('stylus')
3646
}
3747
}
3848

template/webpack.config.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,6 @@ var webpackOptions = {
3333
]
3434
}
3535
},
36-
{
37-
test: /\.css$/,
38-
loader: ExtractTextPlugin.extract({
39-
fallback: "vue-style-loader",
40-
use: ["css-loader"]
41-
})
42-
},
43-
{
44-
test: [/\.scss$/ , /\.sass$/],
45-
loader: ExtractTextPlugin.extract({
46-
fallback: "vue-style-loader",
47-
use: [ 'css-loader?sourceMap', 'less-loader?sourceMap' ]
48-
})
49-
},
50-
{
51-
test: /\.less$/,
52-
loader: ExtractTextPlugin.extract({
53-
fallback: "vue-style-loader",
54-
use: ['css-loader?sourceMap', 'sass-loader?sourceMap' ]
55-
})
56-
},
5736
{
5837
test: /\.js$/,
5938
loader: 'babel-loader',
@@ -95,8 +74,9 @@ var webpackOptions = {
9574
devtool: 'source-map',
9675
}
9776

98-
77+
var buildMode = false;
9978
if (process.env.NODE_ENV === 'production') {
79+
buildMode=true
10080
webpackOptions.externals={
10181
'vue' : 'Vue'
10282
}
@@ -129,4 +109,7 @@ if (process.env.NODE_ENV === 'production') {
129109
}
130110
webpackOptions.entry= './src/main.js';
131111
}
112+
const styleOption = buildMode? { sourceMap: true, extract: true } : { sourceMap: true};
113+
webpackOptions.module.rules = webpackOptions.module.rules.concat(utils.styleLoaders(styleOption}))
114+
132115
module.exports = webpackOptions

0 commit comments

Comments
 (0)