2017-04-30 11:58:25 +00:00
|
|
|
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
2017-08-12 17:03:06 +00:00
|
|
|
import { join } from 'path'
|
2017-04-30 11:58:25 +00:00
|
|
|
|
2017-05-05 15:53:21 +00:00
|
|
|
export function extractStyles () {
|
2017-06-11 14:17:36 +00:00
|
|
|
return !this.options.dev && this.options.build.extractCSS
|
2017-04-30 11:58:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 17:03:06 +00:00
|
|
|
export function styleLoader (ext, loaders = []) {
|
|
|
|
// https://github.com/webpack-contrib/css-loader
|
|
|
|
const cssLoader = {
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
minimize: true,
|
|
|
|
sourceMap: true,
|
|
|
|
// https://github.com/webpack/loader-utils#root-relative-urls
|
|
|
|
root: '~',
|
|
|
|
alias: {
|
|
|
|
'/static': join(this.options.srcDir, 'static'),
|
|
|
|
'/assets': join(this.options.srcDir, 'assets')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/vuejs/vue-style-loader
|
|
|
|
const vueStyleLoader = {
|
|
|
|
loader: 'vue-style-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 15:53:21 +00:00
|
|
|
if (extractStyles.call(this)) {
|
|
|
|
return ExtractTextPlugin.extract({
|
2017-08-12 17:03:06 +00:00
|
|
|
use: [cssLoader].concat(loaders),
|
|
|
|
fallback: vueStyleLoader
|
2017-05-05 15:53:21 +00:00
|
|
|
})
|
2017-04-30 11:58:25 +00:00
|
|
|
}
|
2017-08-12 17:03:06 +00:00
|
|
|
|
|
|
|
return [vueStyleLoader, cssLoader].concat(loaders)
|
2017-04-30 11:58:25 +00:00
|
|
|
}
|