-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild-extension.js
67 lines (60 loc) · 1.83 KB
/
esbuild-extension.js
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
import esbuild from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
import * as fs from 'fs';
const LOCAL_OUT_DIR = 'dist/development';
const EXTENSION_OUT_DIR = '../strigo-academy-chrome-extension/scripts';
const writeBuildResultToExtension = (buildResult) => {
const data = fs.readFileSync('dist/development/strigo.sdk.js', 'utf8');
console.log(`writing built file to "${EXTENSION_OUT_DIR}"`);
fs.writeFileSync(`${EXTENSION_OUT_DIR}/strigo.sdk.js`, data);
console.log('⚡ Styles & Scripts Compiled! ⚡ ');
};
const buildProd = async function () {
return esbuild.build({
entryPoints: [
'src/styles/strigo.scss',
'src/styles/strigo-widget.scss',
'src/styles/strigo-academy-hat.scss',
'src/styles/strigo-assessment-recorder.scss',
'src/strigo.sdk.ts',
],
outdir: 'dist/production',
platform: 'browser',
plugins: [sassPlugin()],
outExtension: { '.js': '.min.js', '.css': '.min.css' },
bundle: true,
minify: true,
define: {
IS_DEVELOPMENT: `"false"`,
},
});
};
const buildDev = async function () {
return esbuild.build({
logLevel: 'debug',
metafile: true,
entryPoints: [
'src/styles/strigo.scss',
'src/styles/strigo-widget.scss',
'src/styles/strigo-academy-hat.scss',
'src/styles/strigo-assessment-recorder.scss',
'src/strigo.sdk.ts',
],
platform: 'browser',
plugins: [sassPlugin()],
outdir: LOCAL_OUT_DIR,
bundle: true,
define: {
IS_DEVELOPMENT: `"false"`,
},
}).then(writeBuildResultToExtension);
};
const build = async function () {
await buildProd();
console.log('⚡ Production Build complete! ⚡');
await buildDev();
console.log('⚡ Development Build complete! ⚡');
};
build()
.then(() => console.log('⚡ Build complete! ⚡'))
.catch(() => process.exit(1));