@tmbr/bundler 1.6.2 → 1.8.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/cli.js +74 -64
- package/package.json +6 -9
package/cli.js
CHANGED
|
@@ -4,11 +4,12 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const exec = require('child_process').execSync;
|
|
6
6
|
const chalk = require('chalk');
|
|
7
|
-
const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
8
|
-
const qrcode = require('qrcode-terminal');
|
|
9
7
|
const server = require('browser-sync').create();
|
|
8
|
+
const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
9
|
+
const silent = require('sass').Logger.silent;
|
|
10
10
|
|
|
11
11
|
const dir = process.cwd();
|
|
12
|
+
const src = path.resolve(dir, 'src');
|
|
12
13
|
const package = require(`${dir}/package.json`);
|
|
13
14
|
const command = process.argv[2];
|
|
14
15
|
|
|
@@ -17,89 +18,98 @@ if (!['build', 'watch'].includes(command)) {
|
|
|
17
18
|
process.exit();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
const logger = (options = {}) => ({
|
|
22
|
+
name: 'logger',
|
|
23
|
+
setup(context) {
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const port = server.getOption('port');
|
|
25
|
-
const proxying = `${host}:${port}`;
|
|
26
|
-
const external = server.getOption('urls').get('external');
|
|
25
|
+
// let reset = true;
|
|
26
|
+
// const path = `${context.initialOptions.outdir}/${Object.keys(context.initialOptions.entryPoints)[0]}`;
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function entryPoints(suffix = '') {
|
|
35
|
-
|
|
36
|
-
if (!suffix.startsWith('.')) {
|
|
37
|
-
suffix = `.${suffix}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const entries = Object.entries({
|
|
41
|
-
admin: path.resolve(dir, './src/admin'),
|
|
42
|
-
main: path.resolve(dir, './src'),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return entries.reduce((result, [name, path]) => {
|
|
46
|
-
if (fs.existsSync(path)) result[`${name}${suffix}`] = path;
|
|
47
|
-
return result;
|
|
48
|
-
}, {});
|
|
49
|
-
}
|
|
28
|
+
context.onStart(() => {
|
|
29
|
+
server.instance.active && server.info();
|
|
30
|
+
});
|
|
50
31
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
context.onEnd(result => {
|
|
33
|
+
if (result.warnings.length || result.errors.length) return console.log('\007');
|
|
34
|
+
// console.log(`${path}.css`);
|
|
35
|
+
// console.log(`${path}.js`);
|
|
36
|
+
// const stats = fs.statSync('main.min.js');
|
|
37
|
+
// const bytes = stats.size;
|
|
38
|
+
// console.log(`build/main.min.js ${bytes / 1000}`);
|
|
39
|
+
// console.log(`build/main.min.css ${Math.round(fs.statSync('build/main.min.css').size / 1000)} KB`);
|
|
40
|
+
// console.log(`build ended with ${result.errors.length} errors`);
|
|
41
|
+
// build/main.min.css 47KB
|
|
42
|
+
// build/main.min.js 170KB
|
|
56
43
|
});
|
|
57
|
-
}
|
|
44
|
+
}
|
|
58
45
|
});
|
|
59
46
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
alias: {'~':
|
|
63
|
-
outdir:
|
|
47
|
+
const buildOptions = {
|
|
48
|
+
entryPoints: {'main.min': src},
|
|
49
|
+
alias: {'~': src},
|
|
50
|
+
outdir: 'build',
|
|
64
51
|
bundle: true,
|
|
65
52
|
minify: true,
|
|
66
53
|
target: 'es2019',
|
|
67
|
-
external: 'jpg,jpeg,webp,png,svg,woff,woff2'.split(',').map(ext => `*.${ext}`),
|
|
54
|
+
external: 'jpg,jpeg,webp,png,gif,svg,woff,woff2'.split(',').map(ext => `*.${ext}`),
|
|
68
55
|
logLevel: 'warning',
|
|
69
56
|
sourcemap: false,
|
|
70
57
|
treeShaking: true,
|
|
71
58
|
legalComments: 'none',
|
|
72
|
-
plugins: [
|
|
59
|
+
plugins: [
|
|
60
|
+
styles({sourceMap: false, logger: silent}),
|
|
61
|
+
logger()
|
|
62
|
+
]
|
|
73
63
|
};
|
|
74
64
|
|
|
75
|
-
const
|
|
76
|
-
entryPoints:
|
|
65
|
+
const watchOptions = Object.assign({}, buildOptions, {
|
|
66
|
+
entryPoints: {'main.dev': src},
|
|
77
67
|
minify: false,
|
|
78
|
-
sourcemap: 'inline',
|
|
79
68
|
logLevel: 'silent',
|
|
80
|
-
|
|
69
|
+
sourcemap: 'inline',
|
|
70
|
+
plugins: [
|
|
71
|
+
styles({sourceMap: true})
|
|
72
|
+
]
|
|
81
73
|
});
|
|
82
74
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
const serveOptions = {
|
|
76
|
+
proxy: `${package.name}.test`,
|
|
77
|
+
files: ['assets/**', 'build/*', '**/*.php'],
|
|
78
|
+
host: 'localhost',
|
|
79
|
+
open: false,
|
|
80
|
+
notify: false,
|
|
81
|
+
logLevel: 'silent',
|
|
82
|
+
injectChanges: false,
|
|
83
|
+
ui: false,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
server.info = function() {
|
|
87
|
+
const host = server.getOption('proxy').get('target');
|
|
88
|
+
const port = server.getOption('port');
|
|
89
|
+
const proxying = `${host}:${port}`;
|
|
90
|
+
const external = server.getOption('urls').get('external');
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
console.clear();
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
95
|
+
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
96
|
+
};
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
async function main() {
|
|
92
99
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
files: ['assets/**', 'build/*', '**/*.php'],
|
|
96
|
-
injectChanges: false,
|
|
97
|
-
host: 'localhost',
|
|
98
|
-
open: false,
|
|
99
|
-
notify: false,
|
|
100
|
-
logLevel: 'silent',
|
|
101
|
-
ui: false,
|
|
102
|
-
};
|
|
100
|
+
const watcher = await esbuild.context(watchOptions);
|
|
101
|
+
const builder = await esbuild.context(buildOptions);
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
if (command === 'build') {
|
|
104
|
+
await watcher.rebuild();
|
|
105
|
+
await builder.rebuild();
|
|
106
|
+
process.exit();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
server.init(serveOptions, () => {
|
|
110
|
+
builder.watch();
|
|
111
|
+
watcher.watch();
|
|
112
|
+
});
|
|
105
113
|
}
|
|
114
|
+
|
|
115
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmbr/bundler",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "https://github.com/TMBR/tmbr-bundler",
|
|
7
|
-
"description": "WordPress development toolkit built on esbuild and browser-sync",
|
|
3
|
+
"version": "1.8.1",
|
|
4
|
+
"repository": "github:TMBR/tmbr-bundler",
|
|
8
5
|
"bin": {
|
|
6
|
+
"bundler": "cli.js",
|
|
9
7
|
"tmbr-bundler": "cli.js"
|
|
10
8
|
},
|
|
11
9
|
"dependencies": {
|
|
12
|
-
"browser-sync": "^2.
|
|
10
|
+
"browser-sync": "^2.28.3",
|
|
13
11
|
"chalk": "^4.1.2",
|
|
14
|
-
"esbuild": "^0.
|
|
15
|
-
"esbuild-sass-plugin": "^2.
|
|
16
|
-
"qrcode-terminal": "^0.12.0"
|
|
12
|
+
"esbuild": "^0.17.11",
|
|
13
|
+
"esbuild-sass-plugin": "^2.6.0"
|
|
17
14
|
}
|
|
18
15
|
}
|