fix css-loader to handle ~/ aliases

#1241
This commit is contained in:
Pooya Parsa 2017-08-12 21:33:06 +04:30
parent 15f9994928
commit 2ff8b5aaf6

View File

@ -1,15 +1,40 @@
import ExtractTextPlugin from 'extract-text-webpack-plugin' import ExtractTextPlugin from 'extract-text-webpack-plugin'
import { join } from 'path'
export function extractStyles () { export function extractStyles () {
return !this.options.dev && this.options.build.extractCSS return !this.options.dev && this.options.build.extractCSS
} }
export function styleLoader (ext, loader = []) { 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
}
}
if (extractStyles.call(this)) { if (extractStyles.call(this)) {
return ExtractTextPlugin.extract({ return ExtractTextPlugin.extract({
use: ['css-loader?minify&sourceMap'].concat(loader), use: [cssLoader].concat(loaders),
fallback: 'vue-style-loader?sourceMap' fallback: vueStyleLoader
}) })
} }
return ['vue-style-loader?sourceMap', 'css-loader?sourceMap'].concat(loader)
return [vueStyleLoader, cssLoader].concat(loaders)
} }