diff --git a/CHANGELOG.md b/CHANGELOG.md index 62ce172..d209109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/bin/bundle.js b/bin/bundle.js index 1fc8c5a..d287fcc 100644 --- a/bin/bundle.js +++ b/bin/bundle.js @@ -1,4 +1,5 @@ import * as esbuild from 'esbuild'; +import * as fs from 'fs'; const args = process.argv.slice(2); @@ -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'); } @@ -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'); } diff --git a/bin/watch.js b/bin/watch.js index 2d0c1fc..a198189 100644 --- a/bin/watch.js +++ b/bin/watch.js @@ -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) { diff --git a/package.json b/package.json index 5105071..75b1d78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "build", - "version": "2.0.5", + "version": "2.0.6", "description": "Frontend build for HTML websites", "type": "module", "repository": { @@ -19,5 +19,8 @@ "express": "^4.16.2", "fs-extra": "^11.1.1", "handlebars": "^4.7.8" + }, + "engine": { + "node": ">=18.18.0" } }