Skip to content
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

Ability to remove leading "/" from built index.html src/href tags #437

Closed
garrett-thompson opened this issue Dec 1, 2017 · 6 comments
Closed

Comments

@garrett-thompson
Copy link

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Running npm run build results in hardcoded src and href values with a leading '/'

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?
I'd like to be able to remove the '/' so that I can access my assets from the same directory the app is served from, not the origin directory.

Example:
App served from https://www.domain.com/folder1/path/app/index.html
App tries to pull assets from https://www.domain.com/
I want them to be pulled from https://www.domain.com/folder1/path/app/

It can be achieved by simply removing the leading '/' from the src or href in the html, but I'd like to make this part of my build process.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information.

  • node version
  • npm version
  • Operating system
@thangngoc89
Copy link
Collaborator

From the look of it, this is not simply a path change. You also have to change how the router work and other stuffs since preact-cli assumes that it will be deployed at top-level path

@developit
Copy link
Member

developit commented Dec 3, 2017

hmm - we need to have explicit (domain-relative) paths for assets because of client-side routing. If a user visits the "about" page of your app (https://www.domain.com/folder1/path/app/about), we need to know that the assets should be loaded from /folder1/path/app/{asset}.

We support setting the "base path" / "mount path" for your application via the homepage option:

preact build --homepage /folder1/path/app/
# or
HOMEPAGE=/folder1/path/app/ npm run build

Perhaps this is what you were looking for?

@garrett-thompson
Copy link
Author

Can I set the homepage to “”?

I’ll play with this. Thanks!

@garrett-thompson
Copy link
Author

HOMEPAGE=/test/path/ doesn't change anything about the assets in the built index.html.

@thangngoc89
Copy link
Collaborator

@mellogarrett it's proposed syntax for changing that. It wasn't implemented (yet)

@developit
Copy link
Member

developit commented Dec 7, 2017

My bad, I thought we had merged the HOMEPAGE bit - you have to use preact.config.js for now:

export default function (config, env, helpers) {
  config.output.publicPath = '/test/path/'
}

To get the result I mentioned above:

export default function (config, env, helpers) {
  config.output.publicPath = process.env.HOMEPAGE
}

(from #323 (comment))

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

No branches or pull requests

4 participants