ssg solution for CanJS 6 custom stache elements
/client-helpers - functions that are safe to use in a browser (and can be imported using node)
/dist - ssg and production spa build
/jsdom-ssg - ssg nodejs logic (not browser-safe)
/mock-can-globals - includes mocks for `can-globals`'s `isNode` and `isBrowserWindow` for `can-route` to function properly
/temp - random js that showcases ideas for implementions
/index.html - dev SPA
/tests - playwright application and tests
/main.js - client side code that generates CanJS 6 components
/production.html - dev SPA
/ssg.json - general ssg configuration (includes routes and default settings) and defines environments
/static-server.js - simple static server to test if ssg, assets, bundles can all be hosted in one spot
/playwright.preset.js - base playwright config that all playwright configs extend
{
// Paths to assets such as images, favicons, etc, they will be copied to dist
"assets": ["assets"],
// Default serve mode. Options: "ssg" and "spa"
"defaultServerMode": "ssg",
// Default environment. Options: "dev" and "prod" (given the current configuration, you can add or remove environments as you need)
"defaultEnv": "dev",
"environments": {
// Environment name (can be whatever you want)
"prod": {
// prebuild (optional) - prebuild script (allows you to run steal-tools)
"prebuild": "prebuild.js",
// dist - All builds will be generated in the /dist/ directory
"dist": {
// mainTag (optional) - steal/main tag specific to builds
"mainTag": "<script src=\"/bundles/can-stache-element-ssr/main.js\" main></script>",
//basePath - sub-directory in /dist/ where all generated build files will go
// /dist/prod
"basePath": "prod",
// static - sub-directory for where ssg pages will be stored
"static": "static",
// assets - sub-directory where all assets will be copied to
"assets": "",
// entryPoint (optional) - path to entry point specific to serving from dist
"entryPoint": "index.html"
},
// entryPoint - path to entry point for serving (if not from dist)
"entryPoint": "production.html",
// serveFromDist (optional) - Determines if serving should use dist or root of project
"serveFromDist": true
}
},
// Routes for generating ssg pages
"routes": [
"http://127.0.0.1:8080",
"http://127.0.0.1:8080/tasks",
"http://127.0.0.1:8080/404"
// ...
]
}
Using setInterval
will cause the build progress for static pages to hang. For more information look into Technical Decisions #3 involving
process.once("beforeExit", (code) => {
// ...
})
Assets directories are defined in ssg.json
. These directories are copied to dist
at build. These include things like images, svgs, favicons, etc and can be imported using relatively or absolutely:
Absolute path normally points at the root of the project
<img src="/assets/image.png">
Relative path is relative based on url and not where the javascript file is found in your project
<!-- url is: http://0.0.0.0:8080/progressive-loading/cow -->
<img src="../assets/image.png">
$ node -v # 14.20.0
$ npm -v # 6.14.17
$ npm install
For dev environment (default)
$ npm run build # Generates dev static pages (default)
# or
$ node jsdom-ssg/index.js # Generates dev static pages (default)
# or
$ SSR_ENVIRONMENT=dev node jsdom-ssg/index.js # Generates dev static pages
# or
$ node jsdom-ssg/index.js --environment dev # Generates dev static pages
generates dist/dev
<-- specific to dev environment and is configurable in ssg.json
For prod environment
$ npm run build-prod # Generates prod static pages
# or
$ SSR_ENVIRONMENT=prod node jsdom-ssg/index.js # Generates prod static pages
# or
$ node jsdom-ssg/index.js --environment prod # Generates prod static pages
generates dist/prod
<-- specific to prod environment and is configurable in ssg.json
Since there's a lot of logic in server.js
, it's hard to trust whether or not it's possible to truly serve all the static pages, assets, bundles from a single directory.
$ npm run static-server # Runs simple static server
To serve in ssg (static) mode where built files from /dist are used by default
$ npm run serve # serves ssg dev application (default)
# or
$ node server.js # serves ssg dev application (default)
# or
$ SSR_ENVIRONMENT=dev SERVER_MODE=ssg node server.js # serves ssg dev application
# or
$ node server.js --environment dev --serverMode ssg # serves ssg dev application
To serve in spa mode where built files from /dist are not used (except dist/404/index.html as needed)
$ npm run serve-dev # serves spa dev application
# or
$ SERVER_MODE=spa node server.js # serves spa dev application
# or
$ SSR_ENVIRONMENT=dev SERVER_MODE=spa node server.js # serves spa dev application
# or
$ node server.js --environment dev --serverMode spa # serves spa dev application