Skip to content

Commit

Permalink
build(html-template): Bundle template at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Jan 15, 2025
1 parent 90e2063 commit 1bd40d5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/html-templates/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Thumbs.db
*.log
yarn.lock
dist
dist-template
artifacts
.env
4 changes: 0 additions & 4 deletions packages/html-templates/index.js

This file was deleted.

5 changes: 3 additions & 2 deletions packages/html-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "@bundle-stats/html-templates",
"version": "4.17.0",
"description": "HTML templates for report generation.",
"main": "index.js",
"main": "dist/index.js",
"types": "types.d.ts",
"scripts": {
"prebuild": "rimraf ./dist",
"build": "cross-env NODE_ENV=production webpack --config webpack.config.production.js --mode production",
"build:template": "cross-env NODE_ENV=production webpack --config webpack.config.production.js --mode production",
"build": "npm run build:template && ./scripts/bundle-template.js",
"lint": "eslint",
"start": "cross-env NODE_ENV=development storybook dev -c ./build/storybook -p 8090",
"test": "echo \"No tests\" && exit 0"
Expand Down
13 changes: 13 additions & 0 deletions packages/html-templates/scripts/bundle-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const ROOT_DIR = path.join(__dirname, '../');
const OUT_DIR = path.join(ROOT_DIR, 'dist');

const template = fs.readFileSync(path.join(ROOT_DIR, 'dist-template', 'index.html'), 'utf8');
const output = `module.exports = decodeURI("${encodeURI(template)}");`;

fs.mkdirSync(OUT_DIR, { recursive: true });
fs.writeFileSync(path.join(OUT_DIR, 'index.js'), output);
4 changes: 3 additions & 1 deletion packages/html-templates/webpack.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const getResolveConfig = require('./build/webpack/resolve');
const appConfig = require('./src/config.json');
const settings = require('./settings');

const { isDevelopment, isProduction, srcDir, distDir } = settings;
const { isDevelopment, isProduction, srcDir } = settings;
const iconSprite = fs.readFileSync(
require.resolve('@bundle-stats/ui/lib-esm/assets/icons.svg'),
'utf-8',
);

const distDir = path.join(__dirname, 'dist-template');

module.exports = merge(
{
context: srcDir,
Expand Down

0 comments on commit 1bd40d5

Please sign in to comment.