加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/ag-grid/ag-grid
克隆/下载
esbuild.config.cjs 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
const esbuild = require('esbuild');
const { umdWrapper } = require('esbuild-plugin-umd-wrapper');
const fs = require('fs/promises');
const path = require('path');
/** @type {import('esbuild').Plugin} */
const postBuildMinificationPlugin = {
name: 'minification-plugin',
setup(build) {
build.initialOptions.metafile = true;
/** @type {Map<string, AbortController>} */
const writeState = new Map();
/** @param {string} outputFile */
const minifyFile = async (outputFile) => {
try {
if (outputFile.endsWith('.map')) return;
writeState.get(outputFile)?.abort();
const abortController = new AbortController();
writeState.set(outputFile, abortController);
const { signal } = abortController;
const contents = await fs.readFile(path.resolve(outputFile), 'utf-8');
if (signal.aborted) return;
const minified = await esbuild.transform(contents, {
minify: true,
sourcemap: true,
});
if (signal.aborted) return;
const { name, ext } = path.parse(outputFile);
const minifiedFile = path.resolve(path.dirname(outputFile), `${name}.min${ext}`);
await Promise.all([
fs.writeFile(minifiedFile, minified.code, { signal }),
fs.writeFile(`${minifiedFile}.map`, minified.map, { signal }),
]);
} catch (e) {
if (e.name !== 'AbortError') throw e;
}
};
build.onEnd(async (result) => {
await Promise.all(Object.keys(result.metafile.outputs).map(minifyFile));
});
},
};
const exportedNames = {
'ag-grid-community': 'agGrid',
'ag-grid-enterprise': 'agGrid',
'ag-grid-charts-enterprise': 'agGrid',
'ag-grid-react': 'AgGridReact',
};
const exportedName = exportedNames[process.env.NX_TASK_TARGET_PROJECT];
const plugins = [];
let outExtension = {};
if (process.env.NX_TASK_TARGET_TARGET?.endsWith('umd')) {
plugins.push(umdWrapper({ libraryName: exportedName }));
outExtension = {
'.cjs': '.js',
};
} else {
outExtension = {
'.cjs': '.cjs.js',
'.js': '.esm.mjs',
};
}
let alias = {};
if (
process.env.NX_TASK_TARGET_PROJECT === 'ag-grid-enterprise' ||
process.env.NX_TASK_TARGET_PROJECT === 'ag-grid-charts-enterprise'
) {
alias = {
'@ag-grid-community/core': 'ag-grid-community',
'@ag-grid-community/client-side-row-model': 'ag-grid-community',
'@ag-grid-community/csv-export': 'ag-grid-community',
'@ag-grid-community/infinite-row-model': 'ag-grid-community',
};
}
plugins.push(postBuildMinificationPlugin);
/** @type {import('esbuild').BuildOptions} */
const options = {
outExtension,
plugins,
alias,
};
module.exports = options;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化