Files
safeImport/src_bundle/index.mjs

84 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-07-09 13:26:51 +01:00
import wp from 'webpack';
import path from 'node:path'
2025-08-01 20:19:24 +01:00
if (process.argv[1] === import.meta.filename) {
console.log("[SafePack] started");
main();
console.log("done");
}
function main() {
const ls = [
'classnames',
'semver',
'ansi-styles',
// 'debug',
// 'supports-color',
'chalk',
'ms',
'minimatch',
'strip-ansi',
'tslib',
'has-flag',
'ansi-regex',
'color-convert',
'color-name',
// 'type-fest',
'string-width'
];
ls.forEach(l => {
wpCompress(l).then(outputFileLocation => {
console.log("[wp] success", outputFileLocation);
}).catch(err => {
console.error("[failed wp]", l);
console.error("[wp] error");
});
});
}
export function wpCompress(l, outputPath = path.resolve('./output/')) {
return new Promise((resolve, reject) => {
2025-07-26 13:44:32 +01:00
const libraryLocation = import.meta.resolve(l);
console.log(libraryLocation);
2025-08-01 20:19:24 +01:00
const outputFile = l + '.bundle.cjs';
2025-07-26 13:44:32 +01:00
// throw Error("5");
wp({
2025-08-01 20:19:24 +01:00
entry: libraryLocation,
2025-07-26 13:44:32 +01:00
mode: 'production',
2025-08-01 20:19:24 +01:00
optimization: {
2025-07-26 13:44:32 +01:00
mangleExports: false,
avoidEntryIife: true,
2025-08-01 20:19:24 +01:00
minimize: false,
2025-07-26 13:44:32 +01:00
},
output: {
path: outputPath,
2025-08-01 20:19:24 +01:00
filename: outputFile,
2025-07-26 13:44:32 +01:00
clean: false,
iife: false,
library: {
type: 'commonjs2',
// name: l
}
// module: true
2025-08-01 20:19:24 +01:00
},
}, (err, stats) => {
2025-07-26 13:44:32 +01:00
if (err || stats.hasErrors()) {
2025-08-01 20:19:24 +01:00
// console.log(err?.stack);
// console.log(stats?.hasErrors());
// console.log(stats?.toJson());
reject(err || stats);
}else{
resolve(path.resolve(outputPath, outputFile));
2025-07-21 17:01:43 +01:00
}
2025-08-01 20:19:24 +01:00
});
});
}
2025-07-26 13:44:32 +01:00