f2e-middle-esbuild
Version:
f2e-server middleware for esbuild
51 lines (50 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultTsconfig = exports.defaultOptions = exports.createExternal = exports.UUID = exports.pathname_fixer = exports.html = void 0;
const path = require("path");
const fs = require("fs");
exports.html = {
analyze: fs.readFileSync(path.join(__dirname, '../pages/analyze.html')).toString()
};
const pathname_fixer = (str = '') => (str.match(/[^/\\]+/g) || []).join('/');
exports.pathname_fixer = pathname_fixer;
const UUID = (prefix = '_') => prefix + Date.now().toFixed(36) + '-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toFixed(36);
exports.UUID = UUID;
const line_import = (item, index) => `import * as Item${index + 1} from '${item}';`;
const line_export = (item, index) => ` '${item}': Item${index + 1},`;
const createExternal = (external) => {
const content = external.map(line_import).join('\n') + `\nmodule.exports = {\n${external.map(line_export).join('\n')}\n};`;
return content;
};
exports.createExternal = createExternal;
const defaultOptions = (root) => {
return {
write: false,
treeShaking: false,
sourcemap: true,
bundle: true,
outdir: 'static',
loader: {
'.tsx': 'tsx',
'.ts': 'ts',
},
format: 'iife',
tsconfig: `${root}/tsconfig.json`,
};
};
exports.defaultOptions = defaultOptions;
const defaultTsconfig = (root) => {
return {
"compilerOptions": {
"moduleResolution": "node",
"module": "esnext",
"resolveJsonModule": true,
"sourceMap": true,
"target": "esnext"
},
"include": [
root
]
};
};
exports.defaultTsconfig = defaultTsconfig;