-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Allow users to specify homepage variable in package.json #315
Conversation
Update master from developit/preact-cli
Merge changes from master
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.
There are a lot of indentation issues in this PR.
The tests are failing, can you please have fix them too. (specifically in build.snapshot.js
)
/cc @lukeed for further thoughts on this.
@reznord Fixed the indentation issues (sorry, tabs vs. spaces). Regarding the failed checks, I can't think of why the service worker check would succeed on Node 6 and fail on Node 8. Unfortunately, I can't actually run the tests locally because I'm on a Windows machine and #262 prevents the I just looked at the pending checks for my latest commit, and the Node 6 check (which succeeded on the previous commit) seems to be failing all over the place. This is very confusing, since the only difference between those two commits was spacing. |
Meanwhile, the most recent Node 8 check is passing this time. |
I'm gonna test this locally in my PC and will let you know. |
@ethanroday the tests pass perfectly in my local machine, tested it on node v6, v7, v8 too. |
Huh. @lukeed? @developit? Any ideas on why these tests would be succeeding locally but failing in Travis? |
Admittedly, I know nothing about our tests 😞 Pinging the resident mastermind @rkostrzewski |
Makes me wonder if we should start a |
Perhaps this could also be solved setting // preact.config.js
export default function (config, env, helpers) {
const BASE_URL = env.production ? '/my-gh-pages-url' : ''
config.output.publicPath = BASE_URL
} |
@lwakefield Correct, I prefer that approach to be honest, but I'm not sure what others feel about it. |
Whatever the outcome, it may not be a bad idea to consolidate as much of the configuration as possible. Currently, it looks like there are 5 different ways to configure the preact-cli build: |
@lwakefield That's actually what I've been doing as a workaround for now, but it leaves one problem unsolved: The path to the service worker is hardcoded as I see your point about there being too many entries for configuration - and this PR just adds another one (in the form of a |
@ethanroday, I agree - I ran into similar issues with // lib/entry.js
if (process.env.NODE_ENV === 'development') {
require('preact/devtools');
} else if ('serviceWorker' in navigator && location.protocol === 'https:') {
navigator.serviceWorker.register(__webpack_public_path__ + 'sw.js');
} EDIT: see master...lwakefield:use-public-path-for-manifest - I can reopen #323 if it makes sense. |
@lwakefield A significantly more elegant solution! One note: in theory, the Webpack public path can be an absolute URL. In those cases, you would need to check to make sure it was the same domain as the current location before attempting to register the service worker. With that change in place, though, I would be happy to abandon this in favor of a re-opened #323. |
I agree. To make things simpler (re: A quick-n-dirty fix is to add: var baseUrl = '<%= htmlWebpackPlugin.options.publicPath %>';
/// entry.js
navigator.serviceWorker.register(baseUrl + 'sw.js'); Exposing/mounting |
@lukeed, are you suggesting just adding |
@rkostrzewski, any thoughts on the failing tests? |
Hi, link rel="manifest" href="/manifest.json" body |
We could use DefinePlugin to make |
I would need to check that it works, but are you thinking of something like: webpack.definePlugin('PUBLIC_PATH', JSON.stringify(__webpack_public_path__)) |
Any idea why the manifest.json is not properly prefixed? Also, shouldn't both the dev an production show the real path ? The homepage option is really useful because any website can set up a PWA version of the site in a separate path. So, the Router integration is also key. |
Guys, any plans to solve this issue in the nearest couple days? I wouldn't want to create a fork for myself because of this... Thanks! |
@rodush hey, for now you can just use |
@reznord It doesn't help, as the SW path is hardcoded in entry.js - |
Ah true, my bad! |
Hey, I reopened #323 as an alternative approach. With respect to #315 (comment), after some experimenting, it is difficult to define |
We decided to go with the path in #323 since it was simpler & doesn't involve any additional Thank you for your PR @ethanroday ❤️ It sparked some good ideas & conversations. We'll be revisiting those points in the near future, but for now, we're just going with the path of least resistance. 🙇 |
homepage
variable inpackage.json
, referring to the public path under which the app is served in production. This may be a relative path or absolute URL, though only the pathname is relevant. The value ofhomepage
is ignored in non-production environments.homepage
as Webpack'spublicPath
.process.env.HOMEPAGE
so users can use the variable in their own code.