mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add extractCSS option
This commit is contained in:
parent
05085cbc99
commit
e148e4b93a
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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',
|
||||||
@ -116,7 +117,7 @@ export function * build () {
|
|||||||
// Check if pages dir exists and warn if not
|
// Check if pages dir exists and warn if not
|
||||||
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
||||||
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 {
|
} else {
|
||||||
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
@ -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({
|
||||||
|
use: ['css-loader?minimize'].concat(loader),
|
||||||
|
fallback: 'vue-style-loader'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return ExtractTextPlugin.extract({
|
return ['vue-style-loader', 'css-loader'].concat(loader)
|
||||||
use: ['css-loader?minimize'].concat(loader),
|
|
||||||
fallback: 'vue-style-loader'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user