-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to nuxt server and apply base path #1746
Open
1nVitr0
wants to merge
14
commits into
advplyr:master
Choose a base branch
from
1nVitr0:feature/nuxt-target-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
883cb46
Merge commit '5286b533347477ae47d4e56f086285019e8095c1' into feature/…
1nVitr0 31dc10b
Add: build client as server instead of static
1nVitr0 eecd8be
Update: run client from server and proxy requests
1nVitr0 7d0401f
CI: update docker image for nuxt server target
1nVitr0 634167a
Remove sortablejs
advplyr 57994ff
Only start ClientRouter for production
advplyr a8b7c56
Fix: server nuxt client directly without proxy
1nVitr0 9a777a8
Style: fix bookshelf texture url
1nVitr0 3c73322
Dependencies: remove http-proxy-middleware
1nVitr0 433876f
Chore: clean up unnecessary arguments
1nVitr0 6d7c33e
CI: Update integration test to nuxt server
1nVitr0 98c117f
Add static dir to pkg
advplyr 228b520
Feature: use nuxt bridge to bundle client
1nVitr0 03ed99d
Fix: build nuxt to commonjs target
1nVitr0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Path = require('path') | ||
const { promises: { readFile, writeFile } } = require('fs') | ||
const { glob } = require('glob') | ||
|
||
/** | ||
* Rewrite PWA manifest paths to include router base path | ||
* @nuxtjs/pwa module does not support a dynamic router base path, | ||
* so we have to rewrite the manifest paths manually | ||
* | ||
* @see https://github.com/nuxt/nuxt/pull/8520 | ||
* @see https://github.com/nuxt-community/pwa-module/issues/435 | ||
*/ | ||
export default function rewritePwaManifest () { | ||
this.nuxt.hook('ready', async ({ options }) => { | ||
// Do not run on build, this is where the manifest is generated | ||
if (options._build) return | ||
|
||
const routerBasePath = options.router.base | ||
const clientDir = Path.join(options.buildDir, 'dist/client') | ||
let rewritten = false | ||
|
||
// Find manifest file generated to the build directory | ||
const manifestPaths = await glob('manifest.*.json', { cwd: clientDir }) | ||
if (manifestPaths.length === 0) { | ||
console.warn(`[PWA] No manifest not found under ${clientDir}/manifest.*.json`) | ||
return | ||
} | ||
|
||
// Rewrite manifest paths for all found manifest files | ||
for (const manifestPath of manifestPaths) { | ||
const manifestJson = await readFile(Path.join(clientDir, manifestPath), 'utf8') | ||
const manifest = JSON.parse(manifestJson) | ||
|
||
const currentBasePath = manifest.start_url.split('?')[0] | ||
|
||
if (currentBasePath !== (routerBasePath || '/')) { | ||
// Rewrite start_url and icons paths | ||
manifest.start_url = `${routerBasePath}${manifest.start_url.slice(currentBasePath.length)}` | ||
for (const icon of manifest.icons) { | ||
const path = icon.src.startsWith('/') ? icon.src.slice(currentBasePath.length) : icon.src | ||
icon.src = `${routerBasePath}${path}` | ||
} | ||
|
||
// Update manifest file | ||
await writeFile(Path.join(clientDir, manifestPath), JSON.stringify(manifest), 'utf8') | ||
rewritten = true | ||
} | ||
} | ||
|
||
if (rewritten) { | ||
console.info('[PWA] Manifest paths rewritten') | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything about this property in the nuxt docs. What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently gets read in the
plugins/favicon.js
plugin (the one I was not so happy about):