mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
Merge remote-tracking branch 'nuxt/dev' into dev
This commit is contained in:
commit
f8f4e785eb
33
bin/nuxt-dev
33
bin/nuxt-dev
@ -84,24 +84,41 @@ function startDev(oldNuxt) {
|
|||||||
const port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
const port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||||
const host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
const host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||||
|
|
||||||
|
// Error handler
|
||||||
|
const onError = (err, nuxt) => {
|
||||||
|
debug('Error while reloading [nuxt.config.js]', err)
|
||||||
|
return Promise.resolve(nuxt) // Wait for next reload
|
||||||
|
}
|
||||||
|
|
||||||
// Load options
|
// Load options
|
||||||
let options = {}
|
let options = {}
|
||||||
try {
|
try {
|
||||||
options = loadNuxtConfig()
|
options = loadNuxtConfig()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
return onError(err, oldNuxt)
|
||||||
return // Wait for next reload
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create nuxt and builder instance
|
// Create nuxt and builder instance
|
||||||
const nuxt = new Nuxt(options)
|
let nuxt
|
||||||
const builder = new Builder(nuxt)
|
let builder
|
||||||
|
try {
|
||||||
|
nuxt = new Nuxt(options)
|
||||||
|
builder = new Builder(nuxt)
|
||||||
|
} catch (err) {
|
||||||
|
return onError(err, nuxt || oldNuxt)
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => builder.build()) // 1- Start build
|
// Start build
|
||||||
.then(() => oldNuxt ? oldNuxt.close() : Promise.resolve()) // 2- Close old nuxt after successful build
|
.then(() => builder.build())
|
||||||
.then(() => nuxt.listen(port, host)) // 3- Start listening
|
// Close old nuxt after successful build
|
||||||
.then(() => nuxt) // 4- Pass new nuxt to watch chain
|
.then(() => oldNuxt ? oldNuxt.close() : Promise.resolve())
|
||||||
|
// Start listening
|
||||||
|
.then(() => nuxt.listen(port, host))
|
||||||
|
// Pass new nuxt to watch chain
|
||||||
|
.then(() => nuxt)
|
||||||
|
// Handle errors
|
||||||
|
.catch((err) => onError(err, nuxt))
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNuxtConfig() {
|
function loadNuxtConfig() {
|
||||||
|
3
examples/style-resources/README.md
Normal file
3
examples/style-resources/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Using build.styleResources with Nuxt.js
|
||||||
|
|
||||||
|
https://nuxtjs.org/examples
|
1
examples/style-resources/assets/resources.scss
Normal file
1
examples/style-resources/assets/resources.scss
Normal file
@ -0,0 +1 @@
|
|||||||
|
$main: #ccc;
|
9
examples/style-resources/nuxt.config.js
Normal file
9
examples/style-resources/nuxt.config.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
build: {
|
||||||
|
styleResources: {
|
||||||
|
patterns: [
|
||||||
|
'./assets/resources.scss'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
examples/style-resources/package.json
Normal file
15
examples/style-resources/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "style-resources",
|
||||||
|
"dependencies": {
|
||||||
|
"nuxt": "latest"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nuxt",
|
||||||
|
"build": "nuxt build",
|
||||||
|
"start": "nuxt start"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"node-sass": "^4.7.2",
|
||||||
|
"sass-loader": "^6.0.6"
|
||||||
|
}
|
||||||
|
}
|
12
examples/style-resources/pages/index.vue
Executable file
12
examples/style-resources/pages/index.vue
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
<style lang="scss">
|
||||||
|
.main {
|
||||||
|
background: $main;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="main">
|
||||||
|
<h1>Welcome!</h1>
|
||||||
|
<p>Background is grey</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
@ -17,11 +17,12 @@ export default {
|
|||||||
if (this.canRender) {
|
if (this.canRender) {
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV === 'development' &&
|
process.env.NODE_ENV === 'development' &&
|
||||||
|
this.$slots.default &&
|
||||||
this.$slots.default.length > 1
|
this.$slots.default.length > 1
|
||||||
) {
|
) {
|
||||||
throw new Error('<no-ssr> You cannot use multiple child components')
|
throw new Error('<no-ssr> You cannot use multiple child components')
|
||||||
}
|
}
|
||||||
return this.$slots.default[0]
|
return this.$slots.default && this.$slots.default[0]
|
||||||
}
|
}
|
||||||
return h('div', { class: { 'no-ssr-placeholder': true } }, this.placeholder)
|
return h('div', { class: { 'no-ssr-placeholder': true } }, this.placeholder)
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,20 @@ export default function styleLoader(ext, loaders = [], isVueLoader = false) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/yenshih/style-resources-loader
|
||||||
|
let styleResourcesLoader
|
||||||
|
if (this.options.build.styleResources) {
|
||||||
|
styleResourcesLoader = {
|
||||||
|
loader: 'style-resources-loader',
|
||||||
|
options: this.options.build.styleResources
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
vueStyleLoader,
|
vueStyleLoader,
|
||||||
cssLoader,
|
cssLoader,
|
||||||
postcssLoader,
|
postcssLoader,
|
||||||
...loaders
|
...loaders,
|
||||||
|
styleResourcesLoader
|
||||||
].filter(l => l)
|
].filter(l => l)
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@
|
|||||||
"server-destroy": "^1.0.1",
|
"server-destroy": "^1.0.1",
|
||||||
"source-map": "^0.6.1",
|
"source-map": "^0.6.1",
|
||||||
"source-map-support": "^0.5.0",
|
"source-map-support": "^0.5.0",
|
||||||
|
"style-resources-loader": "^0.3.0",
|
||||||
"uglifyjs-webpack-plugin": "^1.0.1",
|
"uglifyjs-webpack-plugin": "^1.0.1",
|
||||||
"url-loader": "^0.6.2",
|
"url-loader": "^0.6.2",
|
||||||
"vue": "^2.5.6",
|
"vue": "^2.5.6",
|
||||||
|
@ -43,6 +43,12 @@ test('/css', async t => {
|
|||||||
t.is(window.getComputedStyle(element).color, 'red')
|
t.is(window.getComputedStyle(element).color, 'red')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/postcss', async t => {
|
||||||
|
const window = await nuxt.renderAndGetWindow(url('/css'))
|
||||||
|
const element = window.document.querySelector('div.red')
|
||||||
|
t.is(window.getComputedStyle(element)['background-color'], 'blue')
|
||||||
|
})
|
||||||
|
|
||||||
test('/stateful', async t => {
|
test('/stateful', async t => {
|
||||||
const { html } = await nuxt.renderRoute('/stateful')
|
const { html } = await nuxt.renderRoute('/stateful')
|
||||||
t.true(html.includes('<div><p>The answer is 42</p></div>'))
|
t.true(html.includes('<div><p>The answer is 42</p></div>'))
|
||||||
|
7
test/fixtures/basic/nuxt.config.js
vendored
7
test/fixtures/basic/nuxt.config.js
vendored
@ -15,5 +15,10 @@ module.exports = {
|
|||||||
bad: null,
|
bad: null,
|
||||||
'': true
|
'': true
|
||||||
},
|
},
|
||||||
transition: false
|
transition: false,
|
||||||
|
build: {
|
||||||
|
postcss: [
|
||||||
|
require('postcss-cssnext')()
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
test/fixtures/basic/pages/css.vue
vendored
4
test/fixtures/basic/pages/css.vue
vendored
@ -3,6 +3,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@custom-selector :--red div.red;
|
||||||
|
:--red {
|
||||||
|
background-color: blue;
|
||||||
|
}
|
||||||
.red {
|
.red {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
1
test/fixtures/with-config/nuxt.config.js
vendored
1
test/fixtures/with-config/nuxt.config.js
vendored
@ -19,6 +19,7 @@ module.exports = {
|
|||||||
modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'),
|
modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'),
|
||||||
transition: 'test',
|
transition: 'test',
|
||||||
layoutTransition: 'test',
|
layoutTransition: 'test',
|
||||||
|
loadingIndicator: 'circle',
|
||||||
offline: true,
|
offline: true,
|
||||||
plugins: [
|
plugins: [
|
||||||
'~/plugins/test.js',
|
'~/plugins/test.js',
|
||||||
|
6
test/fixtures/with-config/pages/index.vue
vendored
6
test/fixtures/with-config/pages/index.vue
vendored
@ -4,3 +4,9 @@
|
|||||||
<nuxt-link to="/about">About page</nuxt-link>
|
<nuxt-link to="/about">About page</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
::placeholder {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
17
test/fixtures/with-config/postcss.config.js
vendored
Normal file
17
test/fixtures/with-config/postcss.config.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const path = require('path')
|
||||||
|
const modulesDir = path.join(__dirname, '..', '..', '..', 'node_modules')
|
||||||
|
const rootDir = __dirname
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
'postcss-import': {
|
||||||
|
root: rootDir,
|
||||||
|
path: [
|
||||||
|
rootDir,
|
||||||
|
modulesDir
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'postcss-url': {},
|
||||||
|
'postcss-cssnext': {}
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,11 @@ test('/ (custom build.publicPath)', async t => {
|
|||||||
t.true(html.includes('src="/test/orion/vendor.'))
|
t.true(html.includes('src="/test/orion/vendor.'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/ (custom postcss.config.js)', async t => {
|
||||||
|
const { html } = await nuxt.renderRoute('/')
|
||||||
|
t.true(html.includes('::-webkit-input-placeholder'))
|
||||||
|
})
|
||||||
|
|
||||||
test('/test/ (router base)', async t => {
|
test('/test/ (router base)', async t => {
|
||||||
const window = await nuxt.renderAndGetWindow(url('/test/'))
|
const window = await nuxt.renderAndGetWindow(url('/test/'))
|
||||||
const html = window.document.body.innerHTML
|
const html = window.document.body.innerHTML
|
||||||
|
Loading…
Reference in New Issue
Block a user