Skip to content

Commit 256e8b8

Browse files
committed
feat(app): Allow forcing publicPath on dev mode too (for SPA and PWA only) #4962
1 parent 1fb3c59 commit 256e8b8

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

app/lib/dev-server.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,12 @@ module.exports = class DevServer {
236236

237237
const serverCompilerWatcher = serverCompiler.watch({}, () => {})
238238

239+
const originalAfter = cfg.devServer.after
240+
239241
// start building & launch server
240242
const server = new WebpackDevServer(clientCompiler, {
243+
...cfg.devServer,
244+
241245
after: app => {
242246
if (cfg.ctx.mode.pwa) {
243247
app.use('/manifest.json', (req, res) => {
@@ -254,6 +258,8 @@ module.exports = class DevServer {
254258
maxAge: 0
255259
}))
256260

261+
originalAfter && originalAfter(app)
262+
257263
SsrExtension.getModule().extendApp({
258264
app,
259265

@@ -287,9 +293,7 @@ module.exports = class DevServer {
287293
})
288294

289295
app.get('*', render)
290-
},
291-
292-
...cfg.devServer
296+
}
293297
})
294298

295299
readyPromise.then(() => {

app/lib/quasar-config.js

+31-26
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function encode (obj) {
2424

2525
function formatPublicPath (path) {
2626
if (!path) {
27-
return path
27+
return path || ''
2828
}
2929

3030
if (!path.endsWith('/')) {
@@ -477,14 +477,10 @@ class QuasarConfig {
477477
cfg.build.publicPath =
478478
(this.ctx.prod || cfg.build.forceDevPublicPath) && cfg.build.publicPath && ['spa', 'pwa'].includes(this.ctx.modeName)
479479
? formatPublicPath(cfg.build.publicPath)
480-
: (cfg.build.vueRouterMode !== 'hash' ? '/' : '')
480+
: (cfg.build.vueRouterMode === 'hash' ? '' : '/')
481481

482482
cfg.build.vueRouterBase = formatRouterBase(cfg.build.publicPath)
483483

484-
cfg.build.appBase = cfg.build.vueRouterMode === 'history'
485-
? cfg.build.publicPath
486-
: ''
487-
488484
cfg.sourceFiles = merge({
489485
rootComponent: 'src/App.vue',
490486
router: 'src/router/index',
@@ -539,6 +535,8 @@ class QuasarConfig {
539535
}
540536

541537
if (this.ctx.dev) {
538+
const originalBefore = cfg.devServer.before
539+
542540
cfg.devServer = merge({
543541
publicPath: cfg.build.publicPath,
544542
hot: true,
@@ -551,26 +549,34 @@ class QuasarConfig {
551549
compress: true,
552550
open: true
553551
}, cfg.devServer, {
554-
contentBase: [ appPaths.srcDir ]
552+
contentBase: false,
553+
554+
before: app => {
555+
if (!this.ctx.mode.ssr) {
556+
const express = require('express')
557+
558+
app.use((cfg.build.publicPath || '/') + 'statics', express.static(appPaths.resolve.src('statics'), {
559+
maxAge: 0
560+
}))
561+
562+
if (this.ctx.mode.cordova) {
563+
const folder = appPaths.resolve.cordova(`platforms/${this.ctx.targetName}/platform_www`)
564+
app.use('/', express.static(folder, { maxAge: 0 }))
565+
}
566+
}
567+
568+
originalBefore && originalBefore(app)
569+
}
555570
})
556571

557-
if (this.ctx.mode.ssr) {
558-
cfg.devServer.contentBase = false
559-
}
560-
else if (this.ctx.mode.cordova || this.ctx.mode.electron) {
572+
if (this.ctx.mode.cordova || this.ctx.mode.electron) {
561573
cfg.devServer.open = false
562574

563575
if (this.ctx.mode.electron) {
564576
cfg.devServer.https = false
565577
}
566578
}
567579

568-
if (this.ctx.mode.cordova) {
569-
cfg.devServer.contentBase.push(
570-
appPaths.resolve.cordova(`platforms/${this.ctx.targetName}/platform_www`)
571-
)
572-
}
573-
574580
if (cfg.devServer.open) {
575581
const isMinimalTerminal = require('./helpers/is-minimal-terminal')
576582
if (isMinimalTerminal) {
@@ -682,8 +688,12 @@ class QuasarConfig {
682688
const host = cfg.devServer.host === '0.0.0.0'
683689
? 'localhost'
684690
: cfg.devServer.host
685-
const urlPath = `${cfg.build.vueRouterMode === 'hash' ? (cfg.build.htmlFilename !== 'index.html' ? cfg.build.htmlFilename : '') : ''}`
686-
cfg.build.APP_URL = `http${cfg.devServer.https ? 's' : ''}://${host}:${cfg.devServer.port}/${urlPath}`
691+
692+
const urlPath = cfg.build.vueRouterMode === 'hash'
693+
? (cfg.build.htmlFilename !== 'index.html' ? (cfg.build.publicPath ? '' : '/') + cfg.build.htmlFilename : '')
694+
: ''
695+
696+
cfg.build.APP_URL = `http${cfg.devServer.https ? 's' : ''}://${host}:${cfg.devServer.port}${cfg.build.publicPath}${urlPath}`
687697
}
688698
else if (this.ctx.mode.cordova) {
689699
cfg.build.APP_URL = 'index.html'
@@ -706,13 +716,8 @@ class QuasarConfig {
706716
'process.env': cfg.build.env
707717
}
708718

709-
if (this.ctx.mode.electron) {
710-
if (this.ctx.dev) {
711-
cfg.build.env.__statics = `"${appPaths.resolve.src('statics').replace(/\\/g, '\\\\')}"`
712-
}
713-
}
714-
else {
715-
cfg.build.env.__statics = `"${((this.ctx.prod || cfg.build.forceDevPublicPath) && cfg.build.publicPath) ? cfg.build.publicPath : '/' }statics"`
719+
if (this.ctx.mode.electron && this.ctx.dev) {
720+
cfg.build.env.__statics = `"${appPaths.resolve.src('statics').replace(/\\/g, '\\\\')}"`
716721
}
717722

718723
appFilesValidations(cfg)

app/lib/ssr/html-template.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ module.exports.getIndexHtml = function (template, cfg) {
6969

7070
html = injectSsrInterpolation(html)
7171

72-
if (cfg.build.appBase) {
73-
html = fillBaseTag(html, cfg.build.appBase)
72+
if (cfg.build.publicPath) {
73+
html = fillBaseTag(html, cfg.build.publicPath)
7474
}
7575

7676
if (cfg.build.minify) {

app/lib/webpack/plugin.html-addons.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ module.exports.plugin = class HtmlAddonsPlugin {
3030

3131
apply (compiler) {
3232
compiler.hooks.compilation.tap('webpack-plugin-html-addons', compilation => {
33-
if (this.cfg.build.appBase) {
33+
if (this.cfg.build.publicPath) {
3434
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync('webpack-plugin-html-base-tag', (data, callback) => {
35-
data.html = fillBaseTag(data.html, this.cfg.build.appBase)
35+
data.html = fillBaseTag(data.html, this.cfg.build.publicPath)
3636
callback(null, data)
3737
})
3838
}

0 commit comments

Comments
 (0)