From 1cc2c6b5b0d698a746c7bd786810bc15a6533949 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 17 Aug 2017 21:48:56 +0430 Subject: [PATCH] wChunk --- lib/app/App.vue | 2 +- lib/app/router.js | 2 +- lib/builder/builder.js | 3 ++- lib/common/utils.js | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/app/App.vue b/lib/app/App.vue index 7e37aa7f97..37e6d69b37 100644 --- a/lib/app/App.vue +++ b/lib/app/App.vue @@ -16,7 +16,7 @@ let layouts = { <% var layoutsKeys = Object.keys(layouts); 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 ? ',' : '' %> <% }) %> } diff --git a/lib/app/router.js b/lib/app/router.js index 62b13e094e..8087634ff0 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -20,7 +20,7 @@ function recursiveRoutes(routes, tab, components) { } const _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) { %> diff --git a/lib/builder/builder.js b/lib/builder/builder.js index e6404ca7e8..d727df9d8e 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -10,7 +10,7 @@ import Tapable from 'tappable' import MFS from 'memory-fs' import webpackDevMiddleware from 'webpack-dev-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 Glob from 'glob' import clientWebpackConfig from './webpack/client.config.js' @@ -286,6 +286,7 @@ export default class Builder extends Tapable { hash, r, wp, + wChunk, resolvePath: this.nuxt.resolvePath.bind(this.nuxt), relativeToBuild: this.relativeToBuild } diff --git a/lib/common/utils.js b/lib/common/utils.js index 2dd93deda0..76768071ec 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -84,10 +84,20 @@ export function isPureObject (o) { return !Array.isArray(o) && typeof o === 'object' } +export const isWindows = /^win/.test(process.platform) + export function wp (p) { /* istanbul ignore if */ - if (/^win/.test(process.platform)) { - p = p.replace(/\\/g, '\\\\') + if (isWindows) { + return p.replace(/\\/g, '\\\\') + } + return p +} + +export function wChunk (p) { + /* istanbul ignore if */ + if (isWindows) { + return p.replace(/\//g, '\\') } return p }