vuepress icon indicating copy to clipboard operation
vuepress copied to clipboard

Build with Relative URLs

Open ghost opened this issue 7 years ago • 47 comments

Feature request

If there was a feature to build with relative urls, we could run the files without opening a server. Might be something like: vuepress build --relative

And urls would be like: assets/js/5.3ca37a5b.js instead of: /assets/js/5.3ca37a5b.js

What problem does this feature solve?

Run static files without a server.

Are you willing to work on this yourself?**

Sure.

ghost avatar Sep 04 '18 13:09 ghost

Change you base to ""

ulivz avatar Sep 05 '18 06:09 ulivz

@ulivz I've already tried couple of base configs. And i tried again like yours. It doesn't work. Paths are still start with /. Can you open the issue again? screen shot 2018-09-05 at 16 07 32

ghost avatar Sep 05 '18 13:09 ghost

@atilkan Probably related to #387 (see https://github.com/vuejs/vuepress/issues/387#issuecomment-388082281), also https://github.com/vuejs/vuepress/issues/575 and https://github.com/vuejs/vuepress/issues/667 As i understand vuepress just cannot be used without a static server (see https://github.com/vuejs/vuepress/issues/667#issuecomment-407704352).

petzerhub avatar Sep 05 '18 13:09 petzerhub

@petzerhub I changed paths manually and some of it worked.

ghost avatar Sep 05 '18 13:09 ghost

Since "" is negative, so "" truly doesn't work for now (it will fallback to "/") ...

We need to enhance it.

ulivz avatar Sep 06 '18 01:09 ulivz

What timeframe do you expect for this enhancement? I am about starting a new project and this is really required. (Manually changing the paths later is simply pita - but I'm sure, you guessed that already ;))

tiptronic avatar Oct 27 '18 09:10 tiptronic

Any updates on this? Working on a project that would be perfect for VuePress, but need to build out with relative URLs as the deliverable will live on a Windows Filesystem.

rebz avatar Jan 21 '19 14:01 rebz

It looks to me like this may be supported in html-webpack-plugin 4.0.0 https://github.com/jantimon/html-webpack-plugin/pull/1114

However, vuepress uses a fork https://github.com/vuejs/vuepress/commit/4816bef of that plugin (https://github.com/vuejs/vuepress/issues/1303), so we'd need to update the fork or switch back to html-webpack-plugin

benmccann avatar Feb 01 '19 22:02 benmccann

Any more updates on this?

BernardZhao avatar Mar 13 '19 03:03 BernardZhao

@BernardZhao @atilkan

I wrote a plugin which may satisfy your needs.

vuepress serve docs

And vuepress will build with absolute URLs and then serve them.

shigma avatar Mar 13 '19 04:03 shigma

@BernardZhao @atilkan

I wrote a plugin which may satisfy your needs.

vuepress serve docs

And vuepress will build with absolute URLs and then serve them.

You would still need a server that serves the files though... OP wants to open the generated files straight from disk without any server. This can only be done when the urls are relative.

Waterstraal avatar Mar 14 '19 12:03 Waterstraal

I agree with @Waterstraal, it's not a workaround in many cases, for example when using GitHub pages.

simonbrunel avatar Mar 14 '19 12:03 simonbrunel

I agree with @Waterstraal, it's not a workaround in many cases, for example when using GitHub pages.

Since you are using GitHub pages, why do you need a relative URL? Can you provide a use case for me? I really would like to help but I am not so sure I understand your needs.

shigma avatar Mar 15 '19 17:03 shigma

@Shigma we are deploying our docs in subfolders, per version. For example, v2.8.0 is located at https://www.chartjs.org/docs/2.8.0/, with a latest symbolic link alias (https://www.chartjs.org/docs/latest/). Note that we are currently using GitBook but are considering to switch to VuePress.

simonbrunel avatar Mar 15 '19 17:03 simonbrunel

Simple use-case: collect your pages on localhost without external ip... or in a subfolder on a shared space

tiptronic avatar Mar 15 '19 18:03 tiptronic

@Shigma we are deploying our docs in subfolders, per version. For example, v2.8.0 is located at https://www.chartjs.org/docs/2.8.0/, with a latest symbolic link alias (https://www.chartjs.org/docs/latest/). Note that we are currently using GitBook but are considering to switch to VuePress.

And setting base to /docs/2.8.0/ doesn't work?

shigma avatar Mar 16 '19 01:03 shigma

I'm sure it works setting base (though maybe not with the latest alias), but base can't be hard-coded in the repository since it depends of the current branch / tag (master, 2.7.0, 2.8.0, etc...) and would break testing the docs locally. It can't be set at build time either, because the target sub-path is unknown at that time, the build process being different from the deploy one (and it would also break local builds).

simonbrunel avatar Mar 16 '19 07:03 simonbrunel

@Shigma I don't understand what your problem with relative path is. Hardcoding something to get something else to work is always possible, but I can't imagine VuePress general aim is to hardcode simple things like that.

tiptronic avatar Mar 16 '19 08:03 tiptronic

Posting to show interest in this enhancement.

Besides being useful for opening the site without a server it is also required to properly display websites on IPFS.

alko89 avatar Apr 29 '19 14:04 alko89

Interested in this enhancement as well, emphasizing on generating static files with relative paths for non-server file serving purpose.

Migrating out of gitbook (which is currently hosted in AWS S3) and would minimize the complexity/effort of the migration (e.g. effort on redoing the deployment pipeline)

lenowng avatar May 22 '19 15:05 lenowng

I'm also highly interested in this enhancement. Are there any concrete plans for its implementation?

TGreifenberg avatar Jul 15 '19 07:07 TGreifenberg

Any updates? This is also a strong need for our team because we want to host on our build server.

NanChen6 avatar Jul 18 '19 21:07 NanChen6

My usecase for this is Dash/Zeal/Velocity offline docs. It just renders from file URLs, but has a per-install random string at the start of the URI to separate each docset. It's per install so you can't predict it between systems. Using a base of ./ doesn't work. Using a base of / doesn't work. Serving up the docs doesn't fix the offline portion of the usecase.

I hacked on this for a while, you can certainly get a decent amount of the docs working without JS enabled, but obviously any embedded Vue component won't render in that case.

bitwisecook avatar Jul 26 '19 12:07 bitwisecook

We ran into the absolute base path as well. In our case, our needs in development can be partially satisfied by injecting the basename of the repo directory via a shell environment variable on the package.json script command line, and reading that via process.env to set the dest and base settings in the .vuepress/config.js module. This assumes that the access path matches the path it is built under, which is just a little nuisance of re-building for each of a few different target locations. (This works for one fixed path per content build, but inhibits moving the static content elsewhere or accessing it through concurrent alternative paths.)

mcamiano avatar Nov 22 '19 16:11 mcamiano

Same problem here. Why the heck you need a server to run simple HTML files with a bit of Javascript and Styles? I wrote a documentation for a project which should be shipped with the project and not being hosted somewhere, so the customer must be able to open the documentation without development skills.

renepardon avatar Nov 28 '19 10:11 renepardon

https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/markdown/lib/link.js#L20 seems to suggest that the presence or absence of an absolute path (starting with the http protocol), is being used to infer whether or not the link is intended to be an internal (via vue router) or external link. This may not be the only place this assumption was made, and there may be other slightly tenuous inferences made about the absolute URL pattern - it could be somewhat difficult to allow for a relative URL base unless such inferences are removed. Seems also like that would come with some risk of breaking things elsewhere, but I don't know much about this codebase.

mcamiano avatar Dec 04 '19 13:12 mcamiano

I sent https://github.com/yyx990803/html-webpack-plugin/pull/1, which I believe is necessary for fixing this issue

benmccann avatar Apr 09 '20 17:04 benmccann

I took a look at using Docusaurus instead of Vuepress, but they don't support it either. They provided a much better explanation of why they don't support it though: https://github.com/facebook/docusaurus/issues/448#issuecomment-563973732

benmccann avatar Apr 16 '20 17:04 benmccann

@benmccann That is a poor view rather than explanation. It is more like opening a pdf from your local machine. There are security holes in web too. Do you stop using it?

ghost avatar Apr 16 '20 17:04 ghost

@benmccann I agree with @atilkan - that's not an explanation, but (very, very, outdated) paranoia ;)

tiptronic avatar Apr 16 '20 23:04 tiptronic