-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathesbuild.assets.config.mjs
More file actions
75 lines (72 loc) · 1.91 KB
/
esbuild.assets.config.mjs
File metadata and controls
75 lines (72 loc) · 1.91 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
import dotenv from "dotenv/config";
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import cssModulesPlugin from "esbuild-css-modules-plugin"
import {sassPlugin} from 'esbuild-sass-plugin'
import fse from 'fs-extra';
import chalk from 'chalk';
console.log(chalk.blue('bundling js...'));
// JS assets
esbuild
.build({
entryPoints: [
'assets/src/webpage.txt.js',
'assets/src/webpage.util.txt.js',
],
plugins: [
cssModulesPlugin({
force: true,
emitDeclarationFile: true,
localsConvention: 'camelCaseOnly',
namedExports: true,
inject: false
})
],
format: "iife",
outdir: 'assets',
minify: true,
bundle: true,
keepNames: true, // 保留函数和变量的原始名称
globalName: 'UtilsGlobal' // 设置全局变量的名称
})
.then((result) => {
if (result.errors?.length > 0) {
console.log(chalk.red('bundle js failed: ', result.errors));
} else {
console.log(chalk.green('bundle js success'));
}
})
console.log(chalk.blue('bundling styles...'));
// Style assets
esbuild
.build({
entryPoints: [
'assets/src/obsidian-styles.txt.js',
'assets/src/plugin-styles.txt.js',
],
plugins: [
sassPlugin(),
cssModulesPlugin({
force: true,
emitDeclarationFile: true,
localsConvention: 'camelCaseOnly',
namedExports: true,
inject: false
})
],
format: "iife",
outdir: 'assets',
minify: true,
bundle: true,
keepNames: true, // 保留函数和变量的原始名称
})
.then(result => {
fse.rmSync('./assets/obsidian-styles.txt.js')
fse.rmSync('./assets/plugin-styles.txt.js')
if (result.errors?.length > 0) {
console.log(chalk.red('bundle style failed: ', result.errors));
} else {
console.log(chalk.green('bundle style success'));
}
})