remove 2 dependencies

This commit is contained in:
Sébastien Chopin 2016-11-11 15:30:11 +01:00
parent 4b0b83b782
commit c5c9448a26
10 changed files with 124 additions and 18 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/env node
const co = require('co')
const mkdirp = require('mkdirp-then')
const fs = require('fs-extra')
const pify = require('pify')
const { resolve, join, basename } = require('path')
const { existsSync, writeFile } = require('fs')
const mkdirp = pify(fs.mkdirp)
const rootDir = resolve(process.argv.slice(2)[0] || '.')

View File

@ -0,0 +1,37 @@
<template lang="html">
<div class="loading-page" v-if="loading">
<p>Loading...</p>
</div>
</template>
<script>
export default {
data: () => ({
loading: false
}),
methods: {
start () {
this.loading = true
},
finish () {
this.loading = false
}
}
}
</script>
<style lang="css">
.loading-page {
width: 100%;
height: 100%;
background: white;
position: fixed;
top: 0;
left: 0;
text-align: center;
}
p {
margin-top: 200px;
font-size: 30px;
}
</style>

View File

@ -0,0 +1,3 @@
module.exports = {
loading: 'components/loading'
}

View File

@ -0,0 +1,10 @@
{
"name": "custom-loading",
"description": "",
"dependencies": {
"nuxt": "latest"
},
"scripts": {
"start": "nuxt"
}
}

View File

@ -0,0 +1,26 @@
<template>
<div class="container">
<p>About Page</p>
<router-link to="/">Go to /</router-link>
</div>
</template>
<script>
export default {
data () {
return new Promise((resolve) => {
setTimeout(function () {
resolve({})
}, 1000)
})
}
}
</script>
<style scoped>
.container {
font-size: 20px;
text-align: center;
padding-top: 100px;
}
</style>

View File

@ -0,0 +1,26 @@
<template>
<div class="container">
<p>Hello {{ name }}!</p>
<router-link to="/about">Go to /about</router-link>
</div>
</template>
<script>
export default {
data () {
return new Promise((resolve) => {
setTimeout(function () {
resolve({ name: 'world' })
}, 1000)
})
}
}
</script>
<style scoped>
.container {
font-size: 20px;
text-align: center;
padding-top: 100px;
}
</style>

View File

@ -73,7 +73,7 @@ function render (to, ___, next) {
if (Component._Ctor && Component._Ctor.options) {
Component._Ctor.options.data = Component.data
}
<%= (loading ? 'this.$loading.start && this.$loading.increase(30)' : '') %>
<%= (loading ? 'this.$loading.increase && this.$loading.increase(30)' : '') %>
})
promises.push(promise)
}

View File

@ -3,16 +3,18 @@
const debug = require('debug')('nuxt:build')
const _ = require('lodash')
const co = require('co')
const del = require('del')
const chokidar = require('chokidar')
const fs = require('fs')
const fs = require('fs-extra')
const glob = require('glob-promise')
const hash = require('hash-sum')
const mkdirp = require('mkdirp-then')
const pify = require('pify')
const webpack = require('webpack')
const { createBundleRenderer } = require('vue-server-renderer')
const { join, resolve } = require('path')
const remove = pify(fs.remove)
const readFile = pify(fs.readFile)
const writeFile = pify(fs.writeFile)
const mkdirp = pify(fs.mkdirp)
const r = resolve
const defaults = {
@ -60,7 +62,8 @@ module.exports = function * () {
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`')
process.exit(1)
}
createRenderer.call(this, fs.readFileSync(bundlePath, 'utf8'))
const bundle = yield readFile(bundlePath, 'utf8')
createRenderer.call(this, bundle)
return Promise.resolve()
}
/*
@ -87,9 +90,7 @@ module.exports = function * () {
/*
** Create .nuxt/, .nuxt/components and .nuxt/dist folders
*/
try {
yield del(r(this.dir, '.nuxt'))
} catch (e) {}
yield remove(r(this.dir, '.nuxt'))
yield mkdirp(r(this.dir, '.nuxt/components'))
if (!this.dev) {
yield mkdirp(r(this.dir, '.nuxt/dist'))
@ -157,12 +158,15 @@ function * generateRoutesAndFiles () {
store: this.options.store,
css: this.options.css,
plugins: this.options.plugins.map((p) => r(this.dir, p)),
loading: (this.options.loading === 'string' ? r(this.dir, this.options.loading) : this.options.loading),
loading: (typeof this.options.loading === 'string' ? r(this.dir, this.options.loading) : this.options.loading),
components: {
Loading: r(__dirname, '..', 'app', 'components', 'nuxt-loading.vue'),
ErrorPage: r(__dirname, '..', 'app', 'components', (this.dev ? 'nuxt-error-debug.vue' : 'nuxt-error.vue'))
}
}
if (templateVars.loading === 'string' && templateVars.loading.slice(-4) !== '.vue') {
templateVars.loading = templateVars.loading + '.vue'
}
// Format routes for the lib/app/router.js template
// TODO: check .children
templateVars.router.routes.forEach((route) => {
@ -179,8 +183,6 @@ function * generateRoutesAndFiles () {
if (!this.dev && files.includes('pages/_error.vue')) {
templateVars.components.ErrorPage = r(this.dir, 'pages/_error.vue')
}
const readFile = pify(fs.readFile)
const writeFile = pify(fs.writeFile)
let moveTemplates = templatesFiles.map((file) => {
return readFile(r(__dirname, '..', 'app', file), 'utf8')
.then((fileContent) => {
@ -260,8 +262,11 @@ function webpackRunServer () {
if (err) return reject(err)
console.log('[nuxt:build:server]\n', stats.toString({ chunks: false, colors: true }))
const bundlePath = join(serverConfig.output.path, serverConfig.output.filename)
createRenderer.call(this, fs.readFileSync(bundlePath, 'utf8'))
resolve()
readFile(bundlePath, 'utf8')
.then((bundle) => {
createRenderer.call(this, bundle)
resolve()
})
})
})
}

View File

@ -3,7 +3,7 @@
const debug = require('debug')('nuxt:render')
const _ = require('lodash')
const co = require('co')
const fs = require('fs')
const fs = require('fs-extra')
const pify = require('pify')
const ansiHTML = require('ansi-html')
const serialize = require('serialize-javascript')

View File

@ -1,6 +1,6 @@
{
"name": "nuxt",
"version": "0.3.7",
"version": "0.3.8",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"main": "index.js",
"license": "MIT",
@ -27,7 +27,6 @@
"cross-spawn": "^5.0.1",
"css-loader": "^0.25.0",
"debug": "^2.2.0",
"del": "^2.2.2",
"es6-object-assign": "^1.0.3",
"es6-promise": "^4.0.5",
"extract-text-webpack-plugin": "2.0.0-beta.4",
@ -37,7 +36,6 @@
"hash-sum": "^1.0.2",
"lodash": "^4.16.6",
"lru-cache": "^4.0.1",
"mkdirp-then": "^1.2.0",
"path-to-regexp": "^1.7.0",
"pify": "^2.3.0",
"serialize-javascript": "^1.3.0",