@m00rl0ck/simple-builder 1.0.3 → 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
@@ -95,33 +95,6 @@ function triggerReload() {
95
95
  });
96
96
  }
97
97
 
98
- // ======================
99
- // šŸ‘€ WATCH
100
- // ======================
101
-
102
- function watch() {
103
- const SRC_DIR = path.join(ROOT, 'src');
104
-
105
- build();
106
-
107
- fs.watch(SRC_DIR, { recursive: true }, () => {
108
- console.log('šŸ”„ Rebuilding...');
109
- build();
110
- triggerReload();
111
- });
112
- }
113
-
114
- // ======================
115
- // šŸ‘€ BUILD
116
- // ======================
117
- export function build({ watch }) {
118
- if (!!watch) {
119
- return watch();
120
- } else {
121
- return build();
122
- }
123
- }
124
-
125
98
  // ======================
126
99
  // šŸš€ SERVER
127
100
  // ======================
@@ -138,8 +111,8 @@ const server = http.createServer((req, res) => {
138
111
  // ā–¶ļø START
139
112
  // ======================
140
113
 
141
- export function renServer() {
142
- watch();
114
+ export function renServer({ isProd }) {
115
+ build({ watch: true, isProd })
143
116
 
144
117
  server.listen(PORT, () => {
145
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,15 +114,19 @@ function watch() {
117
114
  // šŸš€ BUILD
118
115
  // ======================
119
116
 
120
- export function build() {
121
- console.log(`\nšŸš€ Build started (${isProd ? 'production' : 'development'})`);
117
+ export function build({ watch, isProd }) {
118
+ if (!!watch) {
119
+ return watch();
120
+ }
121
+
122
+ console.log(`\nšŸš€ Build started (${isProd} ? 'production' : 'development')`);
122
123
 
123
124
  cleanDist();
124
125
  ensureDir(DIST_DIR);
125
126
 
126
- buildJS();
127
- buildCSS();
128
- buildHTML();
127
+ devbuildJS(isProd);
128
+ buildCSS(isProd);
129
+ buildHTML(isProd);
129
130
 
130
131
  console.log(`šŸŽ‰ Build finished\n`);
131
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m00rl0ck/simple-builder",
3
- "version": "1.0.3",
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",