@tmbr/bundler 1.9.2 → 1.10.1
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/README.md +14 -8
- package/cli.js +52 -24
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TMBR Bundler
|
|
2
2
|
|
|
3
|
-
A configurable JavaScript and
|
|
3
|
+
A configurable JavaScript and [SASS](https://sass-lang.com/documentation/) bundler built on [esbuild](https://esbuild.github.io) and [browser-sync](https://browsersync.io). Intended for WordPress development or projects where a CI/CD workflow is not available, allowing for concurrent development and production bundles.
|
|
4
4
|
|
|
5
5
|
**Why [esbuild](https://esbuild.github.io)?**
|
|
6
6
|
|
|
7
|
-
Compared to the mess of webpack loaders and dependencies, esbuild is faster, has better documentation and zero dependencies by default. It was created by Evan Wallace, who built this amazing [WebGL demo](https://madebyevan.com/webgl-water) ...
|
|
7
|
+
Compared to the mess of webpack loaders and dependencies, esbuild is faster, has better documentation and zero dependencies by default. It was created by Evan Wallace, who built this amazing [WebGL demo](https://madebyevan.com/webgl-water) in 2011 ... oh yeah, and he also co-founded [Figma](https://www.figma.com/)!
|
|
8
8
|
|
|
9
|
-
## Installation
|
|
9
|
+
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm install @tmbr/bundler
|
|
12
|
+
npm install --save-dev @tmbr/bundler
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
|
-
`@tmbr/bundler` has two commands - `build` and `watch` - that both create concurrent builds:
|
|
16
|
+
`@tmbr/bundler` has two commands - `build` and `watch` - that both create concurrent builds:
|
|
17
17
|
- `build/main.dev.[css|js]` development version with sourcemaps
|
|
18
18
|
- `build/main.min.[css|js]` minified production version
|
|
19
19
|
|
|
20
|
-
### ``
|
|
21
|
-
|
|
20
|
+
### ``bundler build``
|
|
21
|
+
|
|
22
|
+
This command creates the build files noted above and displays KB sizes for the minified css and js build files.
|
|
23
|
+
|
|
24
|
+
### ``bundler watch``
|
|
25
|
+
|
|
26
|
+
This command will create initial build files noted above and start watching for changes. By default, it will look at the **name** field in your `package.json` file, append `.test` and proxy
|
|
27
|
+
`http://example.test:3000` for auto-reloading.
|
|
22
28
|
|
|
23
29
|
## Configuration
|
|
24
30
|
|
package/cli.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import esbuild from 'esbuild';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import readline from 'readline';
|
|
7
|
+
import { create } from 'browser-sync';
|
|
8
|
+
import { execSync as exec } from 'child_process';
|
|
9
|
+
import { sassPlugin as styles } from 'esbuild-sass-plugin';
|
|
10
|
+
import * as sass from 'sass';
|
|
11
|
+
|
|
12
|
+
const server = create();
|
|
9
13
|
|
|
10
14
|
const cwd = process.cwd();
|
|
11
15
|
const src = path.resolve(cwd, 'src');
|
|
12
|
-
const package = require(`${cwd}/package.json`);
|
|
13
16
|
const command = process.argv[2];
|
|
14
17
|
|
|
15
18
|
if (!['build', 'watch'].includes(command)) {
|
|
@@ -29,13 +32,13 @@ const logger = (options = {}) => ({
|
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
context.onEnd(result => {
|
|
32
|
-
if (result.warnings.length || result.errors.length) return console.log('
|
|
35
|
+
if (result.warnings.length || result.errors.length) return console.log('\\007');
|
|
33
36
|
|
|
34
37
|
const css = `${path}/${slug}.css`;
|
|
35
38
|
const js = `${path}/${slug}.js`;
|
|
36
39
|
|
|
37
|
-
console.log(
|
|
38
|
-
console.log(
|
|
40
|
+
console.log(` ${chalk.green('✓')} ${css} ${Math.round(fs.statSync(css).size / 1000)} KB`);
|
|
41
|
+
console.log(` ${chalk.green('✓')} ${js} ${Math.round(fs.statSync(js).size / 1000)} KB`);
|
|
39
42
|
console.log()
|
|
40
43
|
});
|
|
41
44
|
}
|
|
@@ -54,7 +57,7 @@ const buildOptions = {
|
|
|
54
57
|
treeShaking: true,
|
|
55
58
|
legalComments: 'none',
|
|
56
59
|
plugins: [
|
|
57
|
-
styles({sourceMap: false, logger: silent}),
|
|
60
|
+
styles({sourceMap: false, logger: sass.Logger.silent}),
|
|
58
61
|
logger()
|
|
59
62
|
]
|
|
60
63
|
};
|
|
@@ -70,7 +73,7 @@ const watchOptions = Object.assign({}, buildOptions, {
|
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
const serveOptions = {
|
|
73
|
-
proxy: `${
|
|
76
|
+
proxy: `${process.env.npm_package_name}.test`,
|
|
74
77
|
files: ['assets/**', 'build/*', '**/*.php'],
|
|
75
78
|
host: 'localhost',
|
|
76
79
|
open: false,
|
|
@@ -81,15 +84,33 @@ const serveOptions = {
|
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
server.info = function() {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const proxying = `${host}:${port}`;
|
|
87
|
-
const external = server.getOption('urls').get('external');
|
|
87
|
+
const proxying = this.url();
|
|
88
|
+
const external = this.getOption('urls').get('external');
|
|
88
89
|
|
|
89
90
|
console.clear();
|
|
90
91
|
console.log();
|
|
91
|
-
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
92
|
-
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
92
|
+
console.log(` ➜ ${chalk.bold('Proxying')}: ${chalk.green(proxying)}`);
|
|
93
|
+
console.log(` ➜ ${chalk.bold('External')}: ${chalk.cyan(external || 'offline')}\n`);
|
|
94
|
+
console.log(` ${chalk.bold('Shortcuts')}`);
|
|
95
|
+
|
|
96
|
+
for (const [key, [_, tip]] of Object.entries(shortcuts)) {
|
|
97
|
+
tip && console.log(chalk.grey(` press ${chalk.white.bold(key)} to ${tip}`));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
server.url = function() {
|
|
104
|
+
const host = this.getOption('proxy').get('target');
|
|
105
|
+
const port = this.getOption('port');
|
|
106
|
+
return `${host}:${port}`;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const shortcuts = {
|
|
110
|
+
o: [() => exec(`open ${server.url()}`), 'open in browser'],
|
|
111
|
+
r: [() => server.reload(), 'reload the page'],
|
|
112
|
+
q: [() => process.exit(), 'quit'],
|
|
113
|
+
'\x03': [() => process.exit()],
|
|
93
114
|
};
|
|
94
115
|
|
|
95
116
|
async function main() {
|
|
@@ -106,6 +127,13 @@ async function main() {
|
|
|
106
127
|
server.init(serveOptions, () => {
|
|
107
128
|
builder.watch();
|
|
108
129
|
watcher.watch();
|
|
130
|
+
readline.emitKeypressEvents(process.stdin);
|
|
131
|
+
|
|
132
|
+
process.stdin.setRawMode(true);
|
|
133
|
+
process.stdin.on('keypress', (_, key) => {
|
|
134
|
+
if (!key) return;
|
|
135
|
+
shortcuts[key.sequence]?.[0]();
|
|
136
|
+
});
|
|
109
137
|
});
|
|
110
138
|
}
|
|
111
139
|
|
|
@@ -115,11 +143,11 @@ function extend(options, config) {
|
|
|
115
143
|
}
|
|
116
144
|
|
|
117
145
|
if (fs.existsSync(process.argv[3])) {
|
|
118
|
-
const test = require(`${cwd}/${process.argv[3]}`);
|
|
119
|
-
console.log(extend(watchOptions, test.watch));
|
|
120
|
-
console.log(extend(buildOptions, test.build));
|
|
121
|
-
console.log(extend(serveOptions, test.serve));
|
|
122
|
-
process.exit();
|
|
146
|
+
// const test = require(`${cwd}/${process.argv[3]}`);
|
|
147
|
+
// console.log(extend(watchOptions, test.watch));
|
|
148
|
+
// console.log(extend(buildOptions, test.build));
|
|
149
|
+
// console.log(extend(serveOptions, test.serve));
|
|
150
|
+
// process.exit();
|
|
123
151
|
}
|
|
124
152
|
|
|
125
153
|
main();
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmbr/bundler",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.10.1",
|
|
4
5
|
"repository": "github:TMBR/tmbr-bundler",
|
|
5
6
|
"bin": {
|
|
6
7
|
"bundler": "cli.js",
|
|
7
8
|
"tmbr-bundler": "cli.js"
|
|
8
9
|
},
|
|
9
10
|
"dependencies": {
|
|
10
|
-
"browser-sync": "^2.
|
|
11
|
+
"browser-sync": "^2.29.3",
|
|
11
12
|
"chalk": "^4.1.2",
|
|
12
|
-
"esbuild": "^0.
|
|
13
|
-
"esbuild-sass-plugin": "^2.
|
|
13
|
+
"esbuild": "^0.19.3",
|
|
14
|
+
"esbuild-sass-plugin": "^2.15.0"
|
|
14
15
|
}
|
|
15
16
|
}
|