This commit is contained in:
Pooya Parsa 2017-08-17 21:48:56 +04:30
parent 6d9d949864
commit 1cc2c6b5b0
4 changed files with 16 additions and 5 deletions

View File

@ -16,7 +16,7 @@ let layouts = {
<% <%
var layoutsKeys = Object.keys(layouts); var layoutsKeys = Object.keys(layouts);
layoutsKeys.forEach(function (key, i) { %> layoutsKeys.forEach(function (key, i) { %>
"_<%= key %>": () => import('<%= layouts[key] %>' /* webpackChunkName: "<%= wp('layouts/'+key) %>" */).then(m => m.default || m)<%= (i + 1) < layoutsKeys.length ? ',' : '' %> "_<%= key %>": () => import('<%= layouts[key] %>' /* webpackChunkName: "<%= wChunk('layouts/'+key) %>" */).then(m => m.default || m)<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
<% }) %> <% }) %>
} }

View File

@ -20,7 +20,7 @@ function recursiveRoutes(routes, tab, components) {
} }
const _components = [] const _components = []
const _routes = recursiveRoutes(router.routes, '\t\t', _components) const _routes = recursiveRoutes(router.routes, '\t\t', _components)
uniqBy(_components, '_name').forEach((route) => { %>const <%= route._name %> = () => import('<%= relativeToBuild(route.component) %>' /* webpackChunkName: "pages/<%= wp(route.name) %>" */).then(m => m.default || m) uniqBy(_components, '_name').forEach((route) => { %>const <%= route._name %> = () => import('<%= relativeToBuild(route.component) %>' /* webpackChunkName: "<%= wChunk('pages/' + route.name) %>" */).then(m => m.default || m)
<% }) %> <% }) %>
<% if (router.scrollBehavior) { %> <% if (router.scrollBehavior) { %>

View File

@ -10,7 +10,7 @@ import Tapable from 'tappable'
import MFS from 'memory-fs' import MFS from 'memory-fs'
import webpackDevMiddleware from 'webpack-dev-middleware' import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware' import webpackHotMiddleware from 'webpack-hot-middleware'
import { r, wp, createRoutes, parallel, relativeTo, isPureObject } from 'utils' import { r, wp, wChunk, createRoutes, parallel, relativeTo, isPureObject } from 'utils'
import Debug from 'debug' import Debug from 'debug'
import Glob from 'glob' import Glob from 'glob'
import clientWebpackConfig from './webpack/client.config.js' import clientWebpackConfig from './webpack/client.config.js'
@ -286,6 +286,7 @@ export default class Builder extends Tapable {
hash, hash,
r, r,
wp, wp,
wChunk,
resolvePath: this.nuxt.resolvePath.bind(this.nuxt), resolvePath: this.nuxt.resolvePath.bind(this.nuxt),
relativeToBuild: this.relativeToBuild relativeToBuild: this.relativeToBuild
} }

View File

@ -84,10 +84,20 @@ export function isPureObject (o) {
return !Array.isArray(o) && typeof o === 'object' return !Array.isArray(o) && typeof o === 'object'
} }
export const isWindows = /^win/.test(process.platform)
export function wp (p) { export function wp (p) {
/* istanbul ignore if */ /* istanbul ignore if */
if (/^win/.test(process.platform)) { if (isWindows) {
p = p.replace(/\\/g, '\\\\') return p.replace(/\\/g, '\\\\')
}
return p
}
export function wChunk (p) {
/* istanbul ignore if */
if (isWindows) {
return p.replace(/\//g, '\\')
} }
return p return p
} }