Fix url starting with double slash

This commit is contained in:
Sébastien Chopin 2017-03-16 18:52:38 +01:00
parent 65eeff332e
commit e8056f67eb
4 changed files with 10 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import webpack from 'webpack'
import serialize from 'serialize-javascript' import serialize from 'serialize-javascript'
import { createBundleRenderer } from 'vue-server-renderer' import { createBundleRenderer } from 'vue-server-renderer'
import { join, resolve, sep } from 'path' import { join, resolve, sep } from 'path'
import { isUrl } from './utils'
import clientWebpackConfig from './webpack/client.config.js' import clientWebpackConfig from './webpack/client.config.js'
import serverWebpackConfig from './webpack/server.config.js' import serverWebpackConfig from './webpack/server.config.js'
import chalk from 'chalk' import chalk from 'chalk'
@ -86,7 +87,7 @@ export function options () {
if (this.options.build && !Array.isArray(this.options.build.loaders)) extraDefaults.loaders = defaultsLoaders if (this.options.build && !Array.isArray(this.options.build.loaders)) extraDefaults.loaders = defaultsLoaders
if (this.options.build && !Array.isArray(this.options.build.postcss)) extraDefaults.postcss = defaultsPostcss if (this.options.build && !Array.isArray(this.options.build.postcss)) extraDefaults.postcss = defaultsPostcss
this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults) this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults)
if (this.options.build.publicPath.indexOf('http') === 0 && this.dev) { if (this.dev && isUrl(this.options.build.publicPath)) {
this.options.build.publicPath = defaults.publicPath this.options.build.publicPath = defaults.publicPath
} }
// Production, create server-renderer // Production, create server-renderer

View File

@ -7,7 +7,7 @@ import pify from 'pify'
import pathToRegexp from 'path-to-regexp' import pathToRegexp from 'path-to-regexp'
import _ from 'lodash' import _ from 'lodash'
import { resolve, join, dirname, sep } from 'path' import { resolve, join, dirname, sep } from 'path'
import { promisifyRouteParams } from './utils' import { isUrl, promisifyRouteParams } from './utils'
import { minify } from 'html-minifier' import { minify } from 'html-minifier'
const copy = pify(fs.copy) const copy = pify(fs.copy)
const remove = pify(fs.remove) const remove = pify(fs.remove)
@ -29,7 +29,7 @@ export default function () {
var srcStaticPath = resolve(this.srcDir, 'static') var srcStaticPath = resolve(this.srcDir, 'static')
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist') var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
var distPath = resolve(this.dir, this.options.generate.dir) var distPath = resolve(this.dir, this.options.generate.dir)
var distNuxtPath = join(distPath, (this.options.build.publicPath.indexOf('http') === 0 ? '_nuxt' : this.options.build.publicPath)) var distNuxtPath = join(distPath, (isUrl(this.options.build.publicPath) ? '_nuxt' : this.options.build.publicPath))
return co(function * () { return co(function * () {
/* /*
** Launch build process ** Launch build process

View File

@ -31,6 +31,10 @@ export function urlJoin () {
return [].slice.call(arguments).join('/').replace(/\/+/g, '/').replace(':/', '://') return [].slice.call(arguments).join('/').replace(/\/+/g, '/').replace(':/', '://')
} }
export function isUrl (url) {
return (url.indexOf('http') === 0 || url.indexOf('//') === 0)
}
export function promisifyRouteParams (fn) { export function promisifyRouteParams (fn) {
// If routeParams[route] is an array // If routeParams[route] is an array
if (Array.isArray(fn)) { if (Array.isArray(fn)) {

View File

@ -3,7 +3,7 @@
import vueLoaderConfig from './vue-loader.config' import vueLoaderConfig from './vue-loader.config'
import { defaults } from 'lodash' import { defaults } from 'lodash'
import { join } from 'path' import { join } from 'path'
import { urlJoin } from '../utils' import { isUrl, urlJoin } from '../utils'
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -21,7 +21,7 @@ export default function ({ isClient, isServer }) {
vendor: ['vue', 'vue-router', 'vue-meta'] vendor: ['vue', 'vue-router', 'vue-meta']
}, },
output: { output: {
publicPath: (this.options.build.publicPath.indexOf('http') === 0 ? this.options.build.publicPath : urlJoin(this.options.router.base, this.options.build.publicPath)) publicPath: (isUrl(this.options.build.publicPath) ? this.options.build.publicPath : urlJoin(this.options.router.base, this.options.build.publicPath))
}, },
performance: { performance: {
hints: (this.dev ? false : 'warning') hints: (this.dev ? false : 'warning')