Nuxt/lib/builder/webpack/helpers.js

41 lines
991 B
JavaScript
Raw Normal View History

import ExtractTextPlugin from 'extract-text-webpack-plugin'
import { join } from 'path'
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
}
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({
use: [cssLoader].concat(loaders),
fallback: vueStyleLoader
2017-05-05 15:53:21 +00:00
})
}
return [vueStyleLoader, cssLoader].concat(loaders)
}