This "app archetype" provides for common patterns across all app projects so that each app project can standardize on common development behavior and patterns. Its essentially pre-made patterns for build scripts.
# This runs both the node server and webpack (in hot mode)
$ gulp hot
# Also try `dev` mode when running off battery power and you wish to maximize battery life.
$ gulp dev
Hot mode
enables Hot module reloading(HMR), it is where webpack transpiles your javascript and css code and continues to watch for any changes, and, builds and loads only the code that has changed on disk. It allows you to develop without re-loading your browser page as the changes will be automagically piped in.
# This will run test eslint and your spec tests
$ gulp check
# This will run only your spec tests
$ gulp test-dev
Why can't my test and code changes get automatically run with the tests? Why do the tests take so long to start?
# This will start a webpack-dev-server to hot watch your code and also start a karma test browser that auto-reruns when specs or client code changes.
$ gulp test-watch-all
How do I use and/or view the final build files without minifying/uglifying but also with sourcemaps?
# This will build your code and save to disk, and then start a node server (without using webpack-dev-server).
$ gulp dev-static
# This will start the node server in debug mode so that you can place breakpoints, "debugger" statements, or use `node-inspector`.
$ gulp debug
Run either of the below commands before opening the link.
gulp server-test
gulp dev # (OR) (which includes `server-test`)
gulp hot # (OR) (which includes `server-test`)
This will serve the static assets for test.html
open test.html to view test result.
First we need to add a sw-config.js
file under the app's config
folder.
This file contains two sections:
manifest: {
logo: "./images/icon.png",
title: "Electrode Progressive App",
short_name: "EPA",
start_url: "/"
}
Manifest gives you control over how your web app is installed on user's home screen with short_name, title and logo
properties. You can also specify a starting path to launch your app with start_url
property. Manifest defines how your app appears to the user and more importantly how they can launch it.
cache: {
runtimeCaching: [{
handler: "fastest",
urlPattern: /\/home$/
}, {
handler: "networkFirst",
urlPattern: /getBeer/
}],
staticFileGlobs: ['dist/**/*']
}
Seamlessly cache your static assets or run time routes or cache them together!
Precache your static assets generated by webpack using the staticFileGlobs
property. Or use the runtimeCaching
property to cache specific react routes in from your routes.jsx
.
Once this file is added, running
gulp build
will generate a manifest.json
file inside of dist/js/icons-[hash]
and a service worker file dist/sw.js
.
Service Worker
file is generated during the build step and it will precache all the static resources as per the configuration in sw-config.js
.
Using AboveTheFoldOnlyServerRender
you can avoid caching of certain components inside the crucial pages of your app to make your App shell even lighter.
<AboveTheFoldOnlyServerRender skip={true}>
<div>
this will not be a part of your app shell
</div>
</AboveTheFoldOnlyServerRender>
AboveTheFoldOnlyServerRender example Sample config.js More on PWA