UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).

51 lines (50 loc) 2.24 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import esbuild from 'esbuild'; import { lessLoader } from 'esbuild-plugin-less'; import path from 'path'; import fs from 'fs'; import { getRoot } from '../../utils/fileUtils/base.js'; import { NODE_EXTERNALS } from '../common/constant.js'; const userRoot = getRoot(); const entry = path.resolve(userRoot, 'src/index.js'); const outfile = path.resolve(userRoot, '.dev/pub.js'); export default function () { return __awaiter(this, arguments, void 0, function* (minify = false, customEntry, outputPath) { const entryPoint = customEntry ? path.isAbsolute(customEntry) ? customEntry : path.resolve(userRoot, customEntry) : entry; const outfile = path.resolve(outputPath !== null && outputPath !== void 0 ? outputPath : userRoot, '.dev/pub.js'); const res = yield esbuild.build({ entryPoints: [entryPoint], outfile: outfile, bundle: true, // minifyWhitespace: true, // minifyIdentifiers: true, // minifySyntax: false, minify, splitting: false, format: 'esm', platform: 'browser', external: NODE_EXTERNALS, // @ts-ignore plugins: [lessLoader()], loader: { '.client.js': 'text' } }); let contents = fs.readFileSync(outfile, 'utf-8'); contents = contents.replace(/\/\*![\s\S]*?\*\//g, ''); fs.writeFileSync(outfile, contents); return res; }); }