From 9aeeb2276e32ab8474f4ccaa849594f9e0c8d270 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Tue, 20 Nov 2018 18:12:05 +0100 Subject: [PATCH] fix: fall back to default value when `publicPath` is falsy (#4365) * test: let tests fail * fix: add falsy default fallback * fix(publicPath): force adding trailing slash * fix: also change _publicPath --- packages/config/src/options.js | 12 +++++++++++- test/fixtures/basic/nuxt.config.js | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/config/src/options.js b/packages/config/src/options.js index 448e8d0028..dc242fbf75 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -5,7 +5,7 @@ import defaults from 'lodash/defaults' import pick from 'lodash/pick' import isObject from 'lodash/isObject' import consola from 'consola' -import { isPureObject, isUrl, guardDir, isNonEmptyString } from '@nuxt/common' +import { guardDir, isNonEmptyString, isPureObject, isUrl } from '@nuxt/common' import { getDefaultNuxtConfig } from './config' export function getNuxtConfig(_options) { @@ -53,7 +53,14 @@ export function getNuxtConfig(_options) { // Apply defaults const nuxtConfig = getDefaultNuxtConfig() + nuxtConfig.build._publicPath = nuxtConfig.build.publicPath + + // Fall back to default if publicPath is falsy + if (options.build && !options.build.publicPath) { + options.build.publicPath = undefined + } + defaultsDeep(options, nuxtConfig) // Check srcDir and generate.dir excistence @@ -111,6 +118,9 @@ export function getNuxtConfig(_options) { options.appTemplatePath = path.resolve(options.srcDir, options.appTemplatePath) } + options.build.publicPath = options.build.publicPath.replace(/([^/])$/, '$1/') + options.build._publicPath = options.build._publicPath.replace(/([^/])$/, '$1/') + // Ignore publicPath on dev /* istanbul ignore if */ if (options.dev && isUrl(options.build.publicPath)) { diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index b62044c83e..cc38d9f604 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -70,6 +70,7 @@ export default { ], build: { scopeHoisting: true, + publicPath: '', postcss: { preset: { features: {