Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
smohadjer committed Nov 7, 2023
1 parent 531f72d commit 65a4bca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.6

* Updates bundle.js to watch css and js files in root of css and js folder for files that don't get bundled as they are only used in specific pages.

## 2.0.5

* Updated copy.js to allow copying .css files in 'resources/css' folder to public folder, except files in modules folder which get bundled into styles.css.
Expand Down
19 changes: 19 additions & 0 deletions bin/bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as esbuild from 'esbuild';
import * as fs from 'fs';

const args = process.argv.slice(2);

Expand All @@ -14,12 +15,21 @@ let ctxjs = await esbuild.context({
outfile: 'public/resources/js/bundle.js',
});

const jsRootFiles = fs.readdirSync('app/resources/js').filter(name => name !== '.DS_Store' && name !== 'modules' && name !== 'main.ts').map(item => 'app/resources/js/' + item);
const ctxJSRootFiles = await esbuild.context({
entryPoints: jsRootFiles,
outdir: 'public/resources/js',
});

if (args[0] === 'watch') {
await ctxjs.watch();
await ctxJSRootFiles.watch();
console.log('watching js...');
} else {
await ctxjs.rebuild();
await ctxJSRootFiles.rebuild();
ctxjs.dispose();
ctxJSRootFiles.dispose();
console.log('disposed context');
}

Expand All @@ -39,12 +49,21 @@ let ctxcss = await esbuild.context({
outfile: 'public/resources/css/styles.css',
});

const cssRootFiles = fs.readdirSync('app/resources/css').filter(name => name !== '.DS_Store' && name !== 'modules' && name !== 'styles.css').map(item => 'app/resources/css/'+item);
const ctxCSSRootFiles = await esbuild.context({
entryPoints: cssRootFiles,
outdir: 'public/resources/css',
});

if (args[0] === 'watch') {
await ctxcss.watch();
await ctxCSSRootFiles.watch();
console.log('watching css...');
} else {
await ctxcss.rebuild();
await ctxCSSRootFiles.rebuild();
ctxcss.dispose();
ctxCSSRootFiles.dispose();
console.log('disposed context');
}

11 changes: 7 additions & 4 deletions bin/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ console.log('Watching app folder...');

/* copies assets and resources to public folder */
const copyFile = (filepath) => {
if (filepath.indexOf('resources/css') >= 0) {
console.log('Doing nothing as esbuild watches css files...');
} else if (filepath.indexOf('resources/hbs') >= 0) {
if (filepath.indexOf('resources/css') >= 0 ||
filepath.indexOf('resources/js') >= 0) {
// do nothing as esbuild watches css and js files...
return;
}

if (filepath.indexOf('resources/hbs') >= 0) {
precompileHbsTemplates();
} else {
const source = 'app/' + filepath;
const destination = 'public/' + filepath;

try {
fse.copySync(source, destination);
} catch (err) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build",
"version": "2.0.5",
"version": "2.0.6",
"description": "Frontend build for HTML websites",
"type": "module",
"repository": {
Expand All @@ -19,5 +19,8 @@
"express": "^4.16.2",
"fs-extra": "^11.1.1",
"handlebars": "^4.7.8"
},
"engine": {
"node": ">=18.18.0"
}
}

0 comments on commit 65a4bca

Please sign in to comment.