diff --git a/examples/global-css/nuxt.config.js b/examples/global-css/nuxt.config.js index 2670e946b0..f5ae0a61d1 100644 --- a/examples/global-css/nuxt.config.js +++ b/examples/global-css/nuxt.config.js @@ -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 + } } diff --git a/lib/build.js b/lib/build.js index fe56ac0704..66f38e39b1 100644 --- a/lib/build.js +++ b/lib/build.js @@ -45,6 +45,7 @@ debug.color = 2 const defaults = { analyze: false, + extractCSS: false, publicPath: '/_nuxt/', filenames: { css: 'common.[chunkhash].css', @@ -116,7 +117,7 @@ export function * build () { // Check if pages dir exists and warn if not if (!fs.existsSync(join(this.srcDir, 'pages'))) { if (fs.existsSync(join(this.srcDir, '..', 'pages'))) { - console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console + console.error('> No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?') // eslint-disable-line no-console } else { console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console } diff --git a/lib/webpack/helpers.js b/lib/webpack/helpers.js index 3a43041095..3b67924213 100755 --- a/lib/webpack/helpers.js +++ b/lib/webpack/helpers.js @@ -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 ExtractTextPlugin.extract({ - use: ['css-loader?minimize'].concat(loader), - fallback: 'vue-style-loader' - }) + return ['vue-style-loader', 'css-loader'].concat(loader) } diff --git a/lib/webpack/vue-loader.config.js b/lib/webpack/vue-loader.config.js index 4e2335e42f..094ce139c8 100644 --- a/lib/webpack/vue-loader.config.js +++ b/lib/webpack/vue-loader.config.js @@ -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 diff --git a/test/basic.generate.test.js b/test/basic.generate.test.js index 9b828032f5..3c423f3b84 100644 --- a/test/basic.generate.test.js +++ b/test/basic.generate.test.js @@ -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))