Right now Webpack’s publicPath is hardcoded to /static. We need to add a way to change it. We should allow people to change it when they run npx frontity build.
User Stories
As a Frontity developer
I want to change the publicPath at build time
so that I am not restricted to the /static folder
As a Frontity developer I want to change the publicPath at runtime so that I am not restricted to the /static folder
We developed the first version of the framework for our own use during 2017 and 2018. We did it because we were working with some big Spanish publishers and they wanted to improve the performance and UX of their mobile version. It worked great but they didn’t have access to change the code, so at the beginning of 2019, we decided to discontinue the product and launch an open-source framework. This new version is based on the old one, but we took the opportunity to simplify the APIs and do some performance/size optimizations.
There are still some things we haven’t ported from the all framework, like analytics packages, ads packages, comments packages, AMP support, server extensibility, Slot and Fill extensibility… but all those things were working great in the old version.
Yes, because the HTML changes to accomodate the new publicPath. The publicPath query would need to be removed from the URL of course. I have added a FD for a system called Router Converters which will allow to do so.
Also, take into account that with the Theme Bridge architecture, WordPress should be the one caching (or using a CDN). You don’t want to cache twice because that could lead to invalidation problems.
I wonder if we should add the command name to the ENV variables to avoid collisions:
FRONTITY_DEV_PORT=3001
instead of
FRONTITY_PORT=3001
We already have some clashing names:
FRONTITY_NAME
npx frontity create
npx frontity create-package
Most of them for:
npx frontity dev
npx frontity build
npx frontity serve
If we keep adding commands with args, I guess we may get to a point where someone wants to have more than one ENV variable configured for more than one command but they can’t do it.
The user should always have the chance to set the env variables before running the command, right? So they could do FRONTITY_PORT=3333; npx frontity dev. This works in npm scripts as well. Is there a use case where that’s not the case?
At the same time, we could just go with FRONTITY_DEV_PORT, it’s kinda ugly but it solves the problem and if we think of a better solution we can always still keep backwards compatibility and promote the “new” solution
Yes, but I think a lot of people right now is using dotenv to define their env variables in a .env file, so maybe they want to define all of them for different commands and they clash.
Which, by the way, I think that running dotenv ourselves would be pretty cool. I think is getting the standard. I’ve seen several tools that do it lately, like changesets and docker-compose, and it’s cool not to have to install and run dotenv yourself, just create the .env file.
It would be a problem if you had to use such long names in a command:
FRONTITY_DEV_TARGET='module' FRONTITY_DEV_PORT=3001 FRONTITY_DEV_DONT_OPEN_BROWSER=true npx frontity dev
But why not to use the command arguments in that case?
npx frontity dev --target 'module' --port 3001 --dont-open-browser
Also, I understanded that the use case for the env variables is to change the “default” value of each argument so you can call just npx frontity dev and use whatever values you have specified for the env variables. And you can overwrite those values too passing new arguments explicitly.
My vote is for adding the command to the var names.
This feature has been included in the latest release. It was implemented according to the implementation proposal in this Pull Request, and now Frontity allows dev , build and serve commands to be configured using environment variables.
I made a mistake in my implementation proposal. None of our CLI args are in camelcase (--use-cwd or --no-prompt) and our commands are neither (create-package).
I think we should rename this to --public-path. I’ll make a PR to fix it while maintaining backward compatibility.