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 = { module.exports = {
css: [ css: [
'hover.css/css/hover-min.css', 'hover.css/css/hover-min.css',
{ src: 'bulma', lang: 'sass' }, 'bulma/bulma.sass',
join(__dirname, 'css/main.css') join(__dirname, 'css/main.css')
] ],
build: {
extractCSS: true
}
} }

View File

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

View File

@ -1,15 +1,15 @@
import ExtractTextPlugin from 'extract-text-webpack-plugin' import ExtractTextPlugin from 'extract-text-webpack-plugin'
export function extractStyles (ext) { export function extractStyles () {
return !this.dev && !!this.options.build.extractCSS && this.options.build.extractCSS[ext] !== false return !this.dev && this.options.build.extractCSS
} }
export function styleLoader (ext, loader = []) { export function styleLoader (ext, loader = []) {
if (!extractStyles.call(this, ext)) { if (extractStyles.call(this)) {
return ['vue-style-loader', 'css-loader'].concat(loader)
}
return ExtractTextPlugin.extract({ return ExtractTextPlugin.extract({
use: ['css-loader?minimize'].concat(loader), use: ['css-loader?minimize'].concat(loader),
fallback: 'vue-style-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') 'styl': styleLoader.call(this, 'stylus', 'stylus-loader')
}, },
preserveWhitespace: false, preserveWhitespace: false,
extractCSS: extractStyles.call(this, 'vue') extractCSS: extractStyles.call(this)
} }
// Return the config // Return the config
return config return config

View File

@ -18,7 +18,9 @@ test.before('Init Nuxt.js', async t => {
config.rootDir = rootDir config.rootDir = rootDir
config.dev = false config.dev = false
nuxt = new Nuxt(config) 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')) const serve = serveStatic(resolve(__dirname, 'fixtures/basic/dist'))
server = http.createServer((req, res) => { server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res)) serve(req, res, finalhandler(req, res))