Skip to content

Commit

Permalink
update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
mwood77 committed Feb 24, 2025
1 parent ccf6668 commit ef2da46
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
54 changes: 54 additions & 0 deletions gulp/build-gh-pages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable import/no-extraneous-dependencies */
import {
src, dest, series, parallel,
} from 'gulp';
import concat from 'gulp-concat';
import ejs from 'gulp-ejs';
import rename from 'gulp-rename';
import htmlmin from 'gulp-htmlmin';
import { deleteAsync } from 'del';
import webpack from 'webpack-stream';
import TerserPlugin from 'terser-webpack-plugin';
import { readFile } from 'fs/promises';

const clean = () => deleteAsync(['./docs']);

const BUILD_PATH = './docs/resources';

const webpackOptions = {
mode: 'production',
output: { filename: 'ws.min.js' },
optimization: {
minimize: true,
minimizer: [new TerserPlugin({ extractComments: false })],
},
};

const buildJs = () => src(['server/scripts/index.mjs'])
.pipe(webpack(webpackOptions))
.pipe(dest(BUILD_PATH));

const copyCss = () => src(['server/styles/main.css'])
.pipe(concat('ws.min.css'))
.pipe(dest(BUILD_PATH));

const compressHtml = async () => {
const packageJson = await readFile('package.json');
const { version } = JSON.parse(packageJson);

return src('views/*.ejs')
.pipe(ejs({
production: true,
version,
}, {}, { ext: '.html' })) // Prevents EJS from escaping values
.pipe(rename({ extname: '.html' }))
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('./docs'));
};

const copyOtherFiles = () => src(['server/robots.txt', 'server/manifest.json'], { base: 'server/' })
.pipe(dest('./docs'));

const build = series(clean, parallel(buildJs, copyCss, compressHtml, copyOtherFiles));

export default build;
4 changes: 3 additions & 1 deletion gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import updateVendor from './gulp/update-vendor.mjs';
import publishFrontend from './gulp/publish-frontend.mjs';
import publishFrontend from './gulp/build-gh-pages.mjs';

export {
updateVendor,
publishFrontend,
};

export default publishFrontend;
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"lint": "eslint ./server/scripts/**/*.mjs",
"lint:fix": "eslint --fix ./server/scripts/**/*.mjs",
"start": "nodemon index.js",
"pages": "node dist/index.js",
"build": "rm -rf /dist && node build.mjs"
"build": "gulp"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit ef2da46

Please sign in to comment.