From c5c9448a264327adab3920d07937f819f5c0a3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Fri, 11 Nov 2016 15:30:11 +0100 Subject: [PATCH] remove 2 dependencies --- bin/nuxt-init | 3 +- .../custom-loading/components/loading.vue | 37 +++++++++++++++++++ examples/custom-loading/nuxt.config.js | 3 ++ examples/custom-loading/package.json | 10 +++++ examples/custom-loading/pages/about.vue | 26 +++++++++++++ examples/custom-loading/pages/index.vue | 26 +++++++++++++ lib/app/client.js | 2 +- lib/build/index.js | 29 +++++++++------ lib/nuxt.js | 2 +- package.json | 4 +- 10 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 examples/custom-loading/components/loading.vue create mode 100644 examples/custom-loading/nuxt.config.js create mode 100644 examples/custom-loading/package.json create mode 100644 examples/custom-loading/pages/about.vue create mode 100644 examples/custom-loading/pages/index.vue diff --git a/bin/nuxt-init b/bin/nuxt-init index 02b9f5604..35d2ac6e5 100755 --- a/bin/nuxt-init +++ b/bin/nuxt-init @@ -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] || '.') diff --git a/examples/custom-loading/components/loading.vue b/examples/custom-loading/components/loading.vue new file mode 100644 index 000000000..7e42eed45 --- /dev/null +++ b/examples/custom-loading/components/loading.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/examples/custom-loading/nuxt.config.js b/examples/custom-loading/nuxt.config.js new file mode 100644 index 000000000..1cf642301 --- /dev/null +++ b/examples/custom-loading/nuxt.config.js @@ -0,0 +1,3 @@ +module.exports = { + loading: 'components/loading' +} diff --git a/examples/custom-loading/package.json b/examples/custom-loading/package.json new file mode 100644 index 000000000..8b5caca52 --- /dev/null +++ b/examples/custom-loading/package.json @@ -0,0 +1,10 @@ +{ + "name": "custom-loading", + "description": "", + "dependencies": { + "nuxt": "latest" + }, + "scripts": { + "start": "nuxt" + } +} diff --git a/examples/custom-loading/pages/about.vue b/examples/custom-loading/pages/about.vue new file mode 100644 index 000000000..1712f4eb9 --- /dev/null +++ b/examples/custom-loading/pages/about.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/examples/custom-loading/pages/index.vue b/examples/custom-loading/pages/index.vue new file mode 100644 index 000000000..fcfb70a76 --- /dev/null +++ b/examples/custom-loading/pages/index.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/lib/app/client.js b/lib/app/client.js index ca9bf14d4..9bf7ca06c 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -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) } diff --git a/lib/build/index.js b/lib/build/index.js index 6c8260bbc..2a7a9c95f 100644 --- a/lib/build/index.js +++ b/lib/build/index.js @@ -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() + }) }) }) } diff --git a/lib/nuxt.js b/lib/nuxt.js index 48010a6bf..fa0384429 100644 --- a/lib/nuxt.js +++ b/lib/nuxt.js @@ -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') diff --git a/package.json b/package.json index 7e226e6ae..5b8e824e6 100644 --- a/package.json +++ b/package.json @@ -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",