Skip to content

Commit 64f83b7

Browse files
committed
Vue 2.2 and styles included
1 parent 6ab20cc commit 64f83b7

File tree

11 files changed

+36
-43
lines changed

11 files changed

+36
-43
lines changed

lib/app/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let layouts = {
1212
<%
1313
var layoutsKeys = Object.keys(layouts);
1414
layoutsKeys.forEach(function (key, i) { %>
15-
"_<%= key %>": process.browser ? () => System.import('<%= layouts[key] %>') : require('<%= layouts[key] %>')<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
15+
"_<%= key %>": () => import('<%= layouts[key] %>')<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
1616
<% }) %>
1717
}
1818

lib/app/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function recursiveRoutes(routes, tab, components) {
2323
var _components = []
2424
var _routes = recursiveRoutes(router.routes, '\t\t', _components)
2525
uniqBy(_components, '_name').forEach((route) => { %>
26-
const <%= route._name %> = process.browser ? () => System.import('<%= route.component %>') : require('<%= route.component %>')
26+
const <%= route._name %> = () => import('<%= route.component %>')
2727
<% }) %>
2828

2929
<% if (router.scrollBehavior) { %>

lib/app/server.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { stringify } from 'querystring'
88
import { omit } from 'lodash'
99
import middleware from './middleware'
1010
import { app, router<%= (store ? ', store' : '') %>, NuxtError } from './index'
11-
import { getMatchedComponents, getContext, promiseSeries, promisify, urlJoin } from './utils'
11+
import { getContext, promiseSeries, promisify, urlJoin } from './utils'
1212

1313
const isDev = <%= isDev %>
1414
const _app = new Vue(app)
@@ -51,14 +51,22 @@ export default context => {
5151

5252
<%= (isDev ? 'const s = isDev && Date.now()' : '') %>
5353
let ctx = getContext(context)
54-
let Components = getMatchedComponents(context.route)
55-
<% if (store) { %>
56-
let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null)
57-
if (!(promise instanceof Promise)) promise = Promise.resolve()
58-
<% } else { %>
59-
let promise = Promise.resolve()
60-
<% } %>
61-
return promise
54+
let Components = []
55+
return new Promise((resolve) => {
56+
// Wait for the lazy-routes are loaded
57+
router.onReady(resolve)
58+
})
59+
.then(() => {
60+
Components = router.getMatchedComponents()
61+
// nuxtServerInit
62+
<% if (store) { %>
63+
let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null)
64+
if (!(promise instanceof Promise)) promise = Promise.resolve()
65+
<% } else { %>
66+
let promise = Promise.resolve()
67+
<% } %>
68+
return promise
69+
})
6270
.then(() => {
6371
// Sanitize Components
6472
Components = Components.map((Component) => {
@@ -89,7 +97,7 @@ export default context => {
8997
if (typeof layout === 'function') {
9098
layout = layout(ctx)
9199
}
92-
return _app.setLayout(layout)
100+
return _app.loadLayout(layout).then(() => _app.setLayout(layout))
93101
})
94102
.then((layout) => {
95103
// Call middleware (layout + pages)

lib/build.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ export function options () {
9999
colors: true
100100
}
101101
const serverConfig = getWebpackServerConfig.call(this)
102-
const bundlePath = join(serverConfig.output.path, serverConfig.output.filename)
102+
const bundlePath = join(serverConfig.output.path, 'server-bundle.json')
103103
if (fs.existsSync(bundlePath)) {
104104
const bundle = fs.readFileSync(bundlePath, 'utf8')
105-
createRenderer.call(this, bundle)
105+
createRenderer.call(this, JSON.parse(bundle))
106106
addAppTemplate.call(this)
107107
}
108108
}
@@ -413,11 +413,11 @@ function webpackWatchAndUpdate () {
413413
const mfs = new MFS()
414414
const serverConfig = getWebpackServerConfig.call(this)
415415
const serverCompiler = webpack(serverConfig)
416-
const outputPath = join(serverConfig.output.path, serverConfig.output.filename)
416+
const outputPath = join(serverConfig.output.path, 'server-bundle.json')
417417
serverCompiler.outputFileSystem = mfs
418418
this.webpackServerWatcher = serverCompiler.watch({}, (err) => {
419419
if (err) throw err
420-
createRenderer.call(this, mfs.readFileSync(outputPath, 'utf-8'))
420+
createRenderer.call(this, JSON.parse(mfs.readFileSync(outputPath, 'utf-8')))
421421
})
422422
}
423423

@@ -442,10 +442,10 @@ function webpackRunServer () {
442442
if (err) return reject(err)
443443
console.log('[nuxt:build:server]\n', stats.toString(webpackStats)) // eslint-disable-line no-console
444444
if (stats.hasErrors()) return reject(new Error('Webpack build exited with errors'))
445-
const bundlePath = join(serverConfig.output.path, serverConfig.output.filename)
445+
const bundlePath = join(serverConfig.output.path, 'server-bundle.json')
446446
readFile(bundlePath, 'utf8')
447447
.then((bundle) => {
448-
createRenderer.call(this, bundle)
448+
createRenderer.call(this, JSON.parse(bundle))
449449
resolve()
450450
})
451451
})

lib/nuxt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Nuxt {
4242
},
4343
performance: {
4444
gzip: true,
45-
prefetch: true
45+
prefetch: false
4646
},
4747
build: {}
4848
}

lib/render.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function renderRoute (url, context = {}) {
100100
if (self.options.router.base !== '/') {
101101
HEAD += `<base href="${self.options.router.base}">`
102102
}
103+
HEAD += context.styles
103104
APP += `<script type="text/javascript" defer>window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
104105
const html = self.appTemplate({
105106
HTML_ATTRS: 'n-head-ssr ' + m.htmlAttrs.text(),

lib/webpack/base.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import { isUrl, urlJoin } from '../utils'
1616
export default function ({ isClient, isServer }) {
1717
const nodeModulesDir = join(__dirname, '..', 'node_modules')
1818
let config = {
19-
devtool: 'source-map',
19+
devtool: (this.dev ? 'cheap-module-eval-source-map' : false),
2020
entry: {
2121
vendor: ['vue', 'vue-router', 'vue-meta']
2222
},
2323
output: {
2424
publicPath: (isUrl(this.options.build.publicPath) ? this.options.build.publicPath : urlJoin(this.options.router.base, this.options.build.publicPath))
2525
},
2626
performance: {
27+
maxEntrypointSize: 300000,
2728
hints: (this.dev ? false : 'warning')
2829
},
2930
resolve: {

lib/webpack/client.config.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import webpack from 'webpack'
55
import HTMLPlugin from 'html-webpack-plugin'
66
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin'
77
import PreloadWebpackPlugin from 'preload-webpack-plugin'
8-
import ExtractTextPlugin from 'extract-text-webpack-plugin'
98
import ProgressBarPlugin from 'progress-bar-webpack-plugin'
109
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
1110
import base from './base.config.js'
@@ -82,15 +81,6 @@ export default function () {
8281
// Production client build
8382
if (!this.dev) {
8483
config.plugins.push(
85-
// Use ExtractTextPlugin to extract CSS into a single file
86-
new ExtractTextPlugin({
87-
filename: this.options.build.filenames.css,
88-
allChunks: true
89-
}),
90-
// This is needed in webpack 2 for minifying CSS
91-
new webpack.LoaderOptionsPlugin({
92-
minimize: true
93-
}),
9484
// Minify JS
9585
new webpack.optimize.UglifyJsPlugin({
9686
compress: {

lib/webpack/server.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
import webpack from 'webpack'
4+
import VueSSRPlugin from 'vue-ssr-webpack-plugin'
45
import base from './base.config.js'
56
import { each, uniq } from 'lodash'
67
import { existsSync, readFileSync } from 'fs'
@@ -22,14 +23,17 @@ export default function () {
2223

2324
config = Object.assign(config, {
2425
target: 'node',
25-
devtool: false,
26+
devtool: 'source-map',
2627
entry: resolve(this.dir, '.nuxt', 'server.js'),
2728
output: Object.assign({}, config.output, {
2829
path: resolve(this.dir, '.nuxt', 'dist'),
2930
filename: 'server-bundle.js',
3031
libraryTarget: 'commonjs2'
3132
}),
3233
plugins: (config.plugins || []).concat([
34+
new VueSSRPlugin({
35+
filename: 'server-bundle.json'
36+
}),
3337
new webpack.DefinePlugin(Object.assign(env, {
3438
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
3539
'process.BROWSER_BUILD': false, // deprecated

lib/webpack/vue-loader.config.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ export default function ({ isClient }) {
1919
},
2020
preserveWhitespace: false
2121
}
22-
23-
if (!this.dev && isClient) {
24-
// Use ExtractTextPlugin to extract CSS into a single file
25-
const ExtractTextPlugin = require('extract-text-webpack-plugin')
26-
config.loaders.css = ExtractTextPlugin.extract({ loader: 'css-loader' })
27-
config.loaders.scss = ExtractTextPlugin.extract({ loader: 'css-loader!sass-loader', fallbackLoader: 'vue-style-loader' })
28-
config.loaders.sass = ExtractTextPlugin.extract({ loader: 'css-loader!sass-loader?indentedSyntax', fallbackLoader: 'vue-style-loader' })
29-
config.loaders.stylus = ExtractTextPlugin.extract({ loader: 'css-loader!stylus-loader', fallbackLoader: 'vue-style-loader' })
30-
config.loaders.less = ExtractTextPlugin.extract({ loader: 'css-loader!less-loader', fallbackLoader: 'vue-style-loader' })
31-
}
32-
3322
// Return the config
3423
return config
3524
}

0 commit comments

Comments
 (0)