Add extractCSS option

This commit is contained in:
Sebastien Chopin 2017-05-05 17:53:21 +02:00
parent 05085cbc99
commit e148e4b93a
5 changed files with 19 additions and 13 deletions

View File

@ -3,7 +3,10 @@ const { join } = require('path')
module.exports = {
css: [
'hover.css/css/hover-min.css',
{ src: 'bulma', lang: 'sass' },
'bulma/bulma.sass',
join(__dirname, 'css/main.css')
]
],
build: {
extractCSS: true
}
}

View File

@ -45,6 +45,7 @@ debug.color = 2
const defaults = {
analyze: false,
extractCSS: false,
publicPath: '/_nuxt/',
filenames: {
css: 'common.[chunkhash].css',

View File

@ -1,15 +1,15 @@
import ExtractTextPlugin from 'extract-text-webpack-plugin'
export function extractStyles (ext) {
return !this.dev && !!this.options.build.extractCSS && this.options.build.extractCSS[ext] !== false
export function extractStyles () {
return !this.dev && this.options.build.extractCSS
}
export function styleLoader (ext, loader = []) {
if (!extractStyles.call(this, ext)) {
return ['vue-style-loader', 'css-loader'].concat(loader)
}
if (extractStyles.call(this)) {
return ExtractTextPlugin.extract({
use: ['css-loader?minimize'].concat(loader),
fallback: 'vue-style-loader'
})
}
return ['vue-style-loader', 'css-loader'].concat(loader)
}

View File

@ -23,7 +23,7 @@ export default function ({ isClient }) {
'styl': styleLoader.call(this, 'stylus', 'stylus-loader')
},
preserveWhitespace: false,
extractCSS: extractStyles.call(this, 'vue')
extractCSS: extractStyles.call(this)
}
// Return the config
return config

View File

@ -18,7 +18,9 @@ test.before('Init Nuxt.js', async t => {
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
await nuxt.generate()
try {
await nuxt.generate() // throw an error (of /validate route)
} catch (err) {}
const serve = serveStatic(resolve(__dirname, 'fixtures/basic/dist'))
server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res))