-
Notifications
You must be signed in to change notification settings - Fork 345
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
Port to Parcel bundler #1137
Port to Parcel bundler #1137
Conversation
I probably cannot make the bundling work with dynamically generated We should make sure only data relevant for public will be leaked. And include It might be also cleaner if we move all APIs under |
This directory is not public facing, it contains assets used for building bundles.
It makes the repository slightly cleaner and makes things like linting easier.
* Do not run `npm install` in assets twice when running `dist` script. * Install also PHP dependencies in post-install (re-use the `install-dependencies` target`). * Use node executable from NPM via environment variable, instead of relying for it to be on PATH (which is not the case since NPM 4, see https://docs.npmjs.com/cli/run-script). * Print filename of the generated archive in `dist` script.
Also follow semantic versioning so consumers are better informed about breakage. https://semver.org/
This will allow clients to obtain version of Selfoss and API, as well as the the instance configuration. The configuration options are not part of the public API yet, though. I put it under /api prefix, as we might move the rest of the API there in the future. Increases API version to 2.20.0 – new feature
4860e3d
to
9a20077
Compare
We will try to load fresh configuration from the server each time selfoss is opened and cache it in the localStorage indefinitely. If configuration cannot be feched (e.g. in offline mode), the value from localStorage will be used.
Do Windows still support I will remove it unless someone still wants it. cc @gleroi who introduced this in #609 |
With the latest push, selfoss appears to work when built with Parcel 🎉 Here is the commit message summarizing what has been done and what is to be:
|
msapplication- was introduced mainly for windows phone. With the death of the platform i think it can be safely removed. |
The use of template strings make this commit unusable in older browsers until we start transpiling with Parcel. It is not so bad: https://caniuse.com/#feat=template-literals
So that we can make the templates completely static. Also fix some invalid HTML and meta parity.
These use their own salt so it will make them easier to generate on the client. We still support the old password scheme with separate salt so users did not have to rehash their passwords.
806afac
to
1688e8e
Compare
src/controllers/Index.php
Outdated
$this->view->hash = hash('sha512', \F3::get('salt') . $_POST['password']); | ||
} | ||
echo $this->view->render('templates/hashpassword.phtml'); | ||
echo file_get_contents(BASEDIR . '/public/hashpassword.html'); |
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.
Maybe remove this function and serve the static file from the webserver using rewriting?
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.
I started with /
and I initially wanted to do this but the fact that we use /
for both the page and the API endpoint prevented me from doing this. Then I did not re-evaluate it for the other pages. But since GET /
is not actually a part of public API, GET /items
is, we probably could get away with moving it.
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.
One benefit of sending them through PHP is that we do not have to disable caching in the web server. To not delay this any further, I decided not to keep the current behaviour for now.
This is really interesting for a number of reasons. |
Yeah, I think we might need to go back to Webpack after all. Parcel is currently being completely rewritten to be more configurable and the plug-ins for the old version are not very flexible. WebPack has a plug-in for Workbox straight from the horse’s mouth. I really liked how Parcel has built-in support for hot-module reloading, overlay error reporting and I also felt that the HTML/CSS handling is much better in Parcel since Webpack currently only supports JavaScript and getting a CSS file is a hideous hack, but mischnic/parcel-plugin-sw-cache#22 is a deal breaker. |
By the way this is the service worker which https://github.com/mischnic/parcel-plugin-sw-cache generates.
|
The manifest injection seems to work at least. |
Just like with the `selfoss.config` replacing the `data` attribute lookup, we should use the existing `selfoss.ui._` function. This will make changing the translation method easier in the future.
Setting `<base>` in the HTML files was not actually necessary, since we do not use subdirectories in our front-end routes. When we start using history API, it will not be necessary either, as long as we know the routes. The base URI is therefore only necessary for cookies and RSS feed.
Using asset bundler will allow us to switch to modern JavaScript, build user interface client-side more easily, and develop iteratively thanks to hot module replacement. We chose Parcel over Webpack for simplicity of set up. With this, selfoss no longer supports run-time minification of assets. Instead, developer will need to run `npm run build` to bundle all the dependencies and our files and copy them to the `public/` directory. This means the directory is no longer needed to be writeable at run time (useful for read only locations). Alternately, developer can run `npm run dev` command, which will start a program that will watch selfoss files, rebuild them in the background when changed, and then, refresh the opened page. For common users, there are prebuilt packages available, or they can use user.{css,js} for customization, as before. The routes `GET /` (without AJAX), `GET /password` and `GET /opml` were turned into primitive servers of static HTML files and all the magic is happening client-side. OPML is uploaded completely using XHR and even the password hash is generated client-side. We started using some EcmaScript 6 features like imports, which Parcel will automatically resolve. Languages are imported statically as well, to avoid having to copy them using `parcel-plugin-static-files-copy`. Unfortunately, it requires us to declare them explicitly for Parcel to be able to resolve them. We are using `parcel-plugin-sw-cache`, which uses `workbox` to generate ServiceWorker boilerplate. We do not use the Workbox library, though, as it is not possible to both load it locally (not from CDN) and customize the service worker – we just rely on it to get the list of files into the worker.
Since these are supposed to be editable by user any time and we do not want to require users to install development environment, we will need fetch these files manually and handle cache invalidation ourselves. As a key, we will use their mtimes, which we will pass through the configuration key of `/api/about` endpoint. This is re-fetched whenever selfoss is opened, so we can notice when the files are modified, and we will add them to browser's cache storage. Service worker will ignore those cache keys.
Using asset bundler will allow us to switch to modern JavaScript, build user interface client-side more easily, and develop iteratively thanks to hot module replacement.
I chose Parcel over Webpack for simplicity of set up.
What remains
Determine what to do aboutWe no longer use Workbox library.skipWaiting
, does the workbox-generated service worker have something similar?/api/about
requests and the HTML pages will not be cached regularly since they are returned from PHP (though service worker will still cache them, we will need to set them to network-first?).user.{js,css}
better. Currently, we just throw<script>
and<link rel="stylesheet">
into the DOM, hoping that something will be loaded. I would consider creating empty files in the repository to avoid 404s but there will need to for cache to be invalidated when they are changed as well. Or can we assume user that uses such customization is familiar withCTRL-F5
?What remains for future PRs
Workbox copies its files to thepublic/
directory, and then imports them usingimportScripts
. Would it make sense toimport
it and let Parcel bundle it?node-libs-browser
inhashpassword.js
–bcryptjs
supports using Node’s crypto library which makes Parcel think it should resolve it./api
subdirectory. This will greatly simplify the rewrite rules..htaccess
/nginx conf…?parcel-plugin-static-files-copy
. It will probably make more sense to switch directly to something likeFontAwesome, though.
/api/about
loading.