@m00rl0ck/simple-builder 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -13,5 +13,5 @@ if (args.includes('dev')) {
13
13
  }
14
14
 
15
15
  if (args.includes('serve')) {
16
- runServer();
16
+ args.includes('prod') ? runServer({ isProd: true }) : runServer();
17
17
  }
package/dev-server.js CHANGED
@@ -111,8 +111,8 @@ const server = http.createServer((req, res) => {
111
111
  // ▶️ START
112
112
  // ======================
113
113
 
114
- export function renServer() {
115
- watch();
114
+ export function renServer({ isProd }) {
115
+ build({ watch: true, isProd })
116
116
 
117
117
  server.listen(PORT, () => {
118
118
  console.log(`\n🚀 Dev server running: http://localhost:${PORT}\n`);
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { IN_POINT, NODE_ENV } from '../../env.js';
4
3
  import { minifyJS } from './minify.js';
5
4
  import { minifyCSS } from './minify-css.js';
6
5
  import { bundle } from './bundler.js';
@@ -13,11 +12,9 @@ const ROOT = process.cwd();
13
12
  const SRC_DIR = path.join(ROOT, 'src');
14
13
  const DIST_DIR = path.join(ROOT, 'dist');
15
14
 
16
- const ENTRY = path.join(SRC_DIR, `${IN_POINT}.js`);
15
+ const ENTRY = path.join(SRC_DIR, `index.js`);
17
16
  const HTML_INPUT = path.join(SRC_DIR, 'index.html');
18
17
  const HTML_OUTPUT = path.join(DIST_DIR, 'index.html');
19
-
20
- const isProd = NODE_ENV === 'production';
21
18
  const isWatch = process.argv.includes('--watch');
22
19
 
23
20
  // ======================
@@ -39,7 +36,7 @@ function cleanDist() {
39
36
  // ======================
40
37
  // 📦 BUILD JS
41
38
  // ======================
42
- function buildJS() {
39
+ function buildJS(isProd) {
43
40
  const files = fs.readdirSync(SRC_DIR).filter(f => f.endsWith('.js'));
44
41
 
45
42
  const bundle_result = bundle('./src/app.js');
@@ -48,7 +45,7 @@ function buildJS() {
48
45
  fs.writeFileSync('./dist/bundle.min.js', result);
49
46
  }
50
47
 
51
- function buildCSS() {
48
+ function buildCSS(isProd) {
52
49
  const files = fs.readdirSync(SRC_DIR).filter(f => f.endsWith('.css'));
53
50
 
54
51
  files.forEach(file => {
@@ -73,7 +70,7 @@ function buildCSS() {
73
70
  // 🌐 BUILD HTML
74
71
  // ======================
75
72
 
76
- function buildHTML() {
73
+ function buildHTML(isProd) {
77
74
  let html = fs.readFileSync(HTML_INPUT, 'utf-8');
78
75
 
79
76
  if (isProd) {
@@ -117,19 +114,19 @@ function watch() {
117
114
  // 🚀 BUILD
118
115
  // ======================
119
116
 
120
- export function build({ watch }) {
121
- if (watch) {
117
+ export function build({ watch, isProd }) {
118
+ if (!!watch) {
122
119
  return watch();
123
120
  }
124
121
 
125
- console.log(`\n🚀 Build started (${isProd ? 'production' : 'development'})`);
122
+ console.log(`\n🚀 Build started (${isProd} ? 'production' : 'development')`);
126
123
 
127
124
  cleanDist();
128
125
  ensureDir(DIST_DIR);
129
126
 
130
- buildJS();
131
- buildCSS();
132
- buildHTML();
127
+ devbuildJS(isProd);
128
+ buildCSS(isProd);
129
+ buildHTML(isProd);
133
130
 
134
131
  console.log(`🎉 Build finished\n`);
135
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m00rl0ck/simple-builder",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Zero-dependency JS and CSS bundler with dev server and minifier",
5
5
  "type": "module",
6
6
  "main": "index.js",