bundle-static-assets Command
Note: This command is implemented as part of the
@blognami/bundlerpackage and needs to be included in your project'sdevDependenciesfor it to be available. Projects created withgenerate-projectinclude it automatically.
Interface
The command builds the shell's static assets into the build/static-assets directory:
blognami bundle-static-assetsParameters
No parameters required.
Examples
# Build the static assets
blognami bundle-static-assets
# Build them for a production image (needs no database and no .env.production)
NODE_ENV=production blognami bundle-static-assetsDescription
The bundle-static-assets command prebuilds the shell's JavaScript and CSS so a production server never has to bundle them at runtime:
- Rendering - Renders each asset with the build tooling in
@blognami/bundler - Writing - Saves the output under
build/static-assets/, replacing any files from an earlier build
Outside development and test, start-server serves these prebuilt files. In development and test they are never read: the assets are always built on the fly through @blognami/bundler.
Generated File Structure
build/static-assets/
├── service_worker.js # /service_worker.js
└── _blognami/
└── _shell/
├── window.js # /_blognami/_shell/window.js
├── window.js.map # /_blognami/_shell/window.js.map
├── styles.css # /_blognami/_shell/styles.css
└── service_worker.js.map # /_blognami/_shell/service_worker.js.mapProduction Images
Production images run the command at build time, then remove @blognami/bundler and its build tooling with the other development dependencies:
RUN npm install \
&& NODE_ENV=production npx blognami bundle-static-assets \
&& npm prune --omit=devUpgrading Existing Projects
Older projects do not have @blognami/bundler installed. Add it to devDependencies:
npm install --save-dev @blognami/bundlerWithout the package, and without prebuilt files in build/static-assets/, every asset URL fails with:
Static assets are not built: run "blognami bundle-static-assets" or install @blognami/bundlerRelated Commands
start-server- Serves the prebuilt assets outsidedevelopmentandtestgenerate-static-site- Generate static files, including the shell's assetsgenerate-project- Create projects with@blognami/bundleras a devDependency