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

Add publicPath type of option to generate #1052

Closed
jiv-e opened this Issue Jul 7, 2017 · 8 comments

Comments

Projects
None yet
6 participants
@jiv-e

jiv-e commented Jul 7, 2017

Hi!

I tried to publish generated Nuxt page to Github pages. It is served from a subdirectory: username.gihub.io/projectname. This causes 404s because asset references start with '/'. For example _nuxt folder:
Failed to load resource: the server responded with a status of 404 (Not Found) /_nuxt/1.nuxt.bundle.5b7c88cf02a549fbbf73.js

The path should be: /projectname/_nuxt/1.nuxt.bundle.5b7c88cf02a549fbbf73.js
Or: https://username.gihub.io/projectname/_nuxt/1.nuxt.bundle.5b7c88cf02a549fbbf73.js

I couldn't find any good workaround.

It seems that $ nuxt build has a publicPath option that allows changing the dist folder location. It would be great to have similar option for $nuxt generate also. Default could be '/' but changing it to '/projectname/' would solve the problem in Github pages case. This path should also be prepended in the head section of nuxt.config.js where references to local files are made.

This question is available on Nuxt.js community (#c917)
@pi0

This comment has been minimized.

Show comment
Hide comment
@pi0

pi0 Jul 7, 2017

Member

Hey. You have to use router.base

Member

pi0 commented Jul 7, 2017

Hey. You have to use router.base

@pi0 pi0 closed this Jul 7, 2017

@jiv-e

This comment has been minimized.

Show comment
Hide comment
@jiv-e

jiv-e Jul 8, 2017

Great, thanks!

jiv-e commented Jul 8, 2017

Great, thanks!

@sen0rxol0

This comment has been minimized.

Show comment
Hide comment
@sen0rxol0

sen0rxol0 Jul 12, 2017

Having the same problem i guess...
the publicPath should not be absolute when generated, the trailing slash is always added.

i currently have publicPath: 'app/' but it will generate to src='/app/1.app.js.

the thing is publicPath is expected to be a url or absolute path when served, since in a server the url will be parsed, app/ or /app/ will parse to https://app.dev/app/

i thought maybe providing a empty string as router base would solve it but it didn't, guess no way of testing it locally !

sen0rxol0 commented Jul 12, 2017

Having the same problem i guess...
the publicPath should not be absolute when generated, the trailing slash is always added.

i currently have publicPath: 'app/' but it will generate to src='/app/1.app.js.

the thing is publicPath is expected to be a url or absolute path when served, since in a server the url will be parsed, app/ or /app/ will parse to https://app.dev/app/

i thought maybe providing a empty string as router base would solve it but it didn't, guess no way of testing it locally !

@breath103

This comment has been minimized.

Show comment
Hide comment
@breath103

breath103 Oct 13, 2017

one other problem with is that this also affects fragment routing such as <a href="#id"></a>
this won't work unless you do something like <a href="/currentPath#id"></a>, which is silly and complicated i have to say.

breath103 commented Oct 13, 2017

one other problem with is that this also affects fragment routing such as <a href="#id"></a>
this won't work unless you do something like <a href="/currentPath#id"></a>, which is silly and complicated i have to say.

@pi0

This comment has been minimized.

Show comment
Hide comment
@MartinX3

This comment has been minimized.

Show comment
Hide comment
@MartinX3

MartinX3 May 14, 2018

I need to set a publicPath.
Just setting the router base isn't enough.
It need to be /_nuxt/ for netlify
and it need to be the absolute address, if I build it on travis-ci for gh-pages.
How to do that dynamically?

MartinX3 commented May 14, 2018

I need to set a publicPath.
Just setting the router base isn't enough.
It need to be /_nuxt/ for netlify
and it need to be the absolute address, if I build it on travis-ci for gh-pages.
How to do that dynamically?

@aldarund

This comment has been minimized.

Show comment
Hide comment
@aldarund

aldarund May 28, 2018

Contributor

@MartinX3 in build extend
config.output.publicPath = `https://s3.${awsRegion}.amazonaws.com/${awsS3AssetsBucketName}/

Contributor

aldarund commented May 28, 2018

@MartinX3 in build extend
config.output.publicPath = `https://s3.${awsRegion}.amazonaws.com/${awsS3AssetsBucketName}/

@MartinX3

This comment has been minimized.

Show comment
Hide comment
@MartinX3

MartinX3 May 29, 2018

@aldarund
Thank you, but I don't use amazon.
There I implemented a working solution:
https://github.com/MartinX3/nuxt-starter

MartinX3 commented May 29, 2018

@aldarund
Thank you, but I don't use amazon.
There I implemented a working solution:
https://github.com/MartinX3/nuxt-starter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment