forked from iam-medvedev/esbuild-plugin-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
36 lines (33 loc) · 948 Bytes
/
build.ts
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
import * as path from 'path';
import esbuild, { BuildOptions } from 'esbuild';
import { lessLoader } from '../src/index';
// isProduction flag for watch mode
const isProduction = process.env.NODE_ENV === 'production';
const entryPoints = [path.resolve(__dirname, 'index.ts'), path.resolve(__dirname, 'index.less')];
const entryPoint = process.argv.includes('--less') ? entryPoints[1] : entryPoints[0];
(async () => {
const buildOptions: BuildOptions = {
entryPoints: [entryPoint],
bundle: true,
outdir: path.resolve(__dirname, 'output'),
plugins: [
lessLoader({
globalVars: {
primaryColor: '#ff0000',
},
}),
],
loader: {
'.ts': 'ts',
'.png': 'base64',
'.jpg': 'base64',
},
};
if (isProduction) {
await esbuild.build(buildOptions);
} else {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
}
console.log('Done');
})();