-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusemin.ts
More file actions
133 lines (105 loc) · 3.39 KB
/
usemin.ts
File metadata and controls
133 lines (105 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
esbuild plugin: https://github.com/oliverkuchies/esbuild-usemin
https://esm.sh/usemin@0.6.0
https://esm.sh/usemin-cli@0.6.0
https://github.com/nelsyeung/usemin
var defaults = {
output: false, // HTML output path. If false, it will be printed to the console (string)
configFile: false, // config file path for UglifyJS, CleanCSS and HTML minifier (string)
config: false, // UglifyJS, CleanCSS and HTML minifier configs,
// similar format to the config file (object)
htmlmin: false, // Whether to minify the input HTML file (Boolean)
noprocess: false, // Do not process files, just replace references (Boolean)
removeLivereload: false, // Remove livereload script (Boolean)
};
var html = usemin('src/index.html', 'dist');
usemin('src/index.html', 'dist', {
output: 'dist/index.html',
htmlmin: true,
removeLivereload: true,
});
*/
// import * as esbuild from 'https://esm.sh/esbuild'
import * as path from "https://deno.land/std@0.201.0/path/mod.ts";
import { existsSync } from "https://deno.land/std@0.200.0/fs/mod.ts";
import * as esbuild from "https://deno.land/x/esbuild@v0.19.2/mod.js";
import usemin from 'https://esm.sh/gh/oliverkuchies/esbuild-usemin';
import { denoPlugins } from "./plugins/esbuild_deno_loader/mod.ts";
import pluginVue from "https://esm.sh/esbuild-plugin-vue-next";
import { brightGreen } from "https://deno.land/std@0.200.0/fmt/colors.ts";
const args = Deno.args
if(!args[0] || !existsSync(args[0])) {
throw new Error('Require file name. Usage: usemin index.html');
}
const cwd = Deno.cwd();
const dirname = path.resolve(path.dirname(args[0])) || cwd;
const outdir = path.join(dirname, 'dist');
console.log('esbuildOpt.outdir:', outdir);
const denoJson = Deno.env.get('DENO_JSON') ?? "deno.json";
const denoPluginOpts: DenoPluginOpts = { context: new Object };
const denoJsonFile = path.join(dirname, denoJson);
if (existsSync(denoJsonFile)) {
denoPluginOpts.configPath = denoJsonFile;
console.log('deno.json: ', denoPluginOpts.configPath);
} else if (existsSync(path.join(cwd, denoJson))) {
denoPluginOpts.configPath = path.join(cwd, denoJson);
console.log('deno.json: ', denoPluginOpts.configPath);
}
const result = await esbuild.build({
entryPoints: [
{
out: 'dist',
in: args[0] || '.'
}
],
// write: false,
outdir: outdir,
bundle: true,
format: 'esm',
splitting: true,
platform: 'neutral',
external: ['require', 'fs', 'path'],
plugins: [
pluginVue({
templateOptions: 'compile',
}),
...denoPlugins(denoPluginOpts),
usemin({
read_only: false,
file_types: ['html', 'php', 'cshtml', 'hbs'],
outdir: outdir,
})
]
});
if (result.outputFiles) console.log(result.outputFiles.map(o => o.text.toString()));
//console.log(result);
esbuild.stop();
console.log(brightGreen("Done"));
/*
await esbuild.build({
entryPoints: [
{
out: 'sample.dist',
in: 'test/sample/sample.php'
},
],
outdir: outdir,
bundle: true,
platform: 'node',
external: ['require', 'fs', 'path'],
plugins: [
usemin({
read_only: false,
file_types: ['php', 'html'],
outdir: outdir,
})
],
format: 'iife',
minify: true,
target: ['es2022']
});
*/
interface DenoPluginOpts {
configPath?: string
context?: object
};