javascript - 汇总可选输入
问题描述
如果找不到输入,汇总中有没有办法跳过输入?目前,Error: Could not resolve entry module (src/index.js)
一旦找不到文件,构建就会失败。
我浏览了文档并四处搜索,但似乎找不到实现此目的的选项或钩子。在下面的简化示例中,我想在找不到page.js
时继续下一个构建。src/index.js
export default [
{
input: 'src/index.js',
output: [
{
file: 'dist/esm/index.esm.js',
format: 'esm',
},
{
file: 'dist/cjs/index.js',
format: 'cjs',
},
],
plugins: [
// ...
],
},
{
input: 'page.js',
output: [
{
file: 'dist/esm/page.esm.js',
format: 'esm',
},
{
file: 'dist/cjs/page.js',
format: 'cjs',
},
],
plugins: [
// ...
],
},
];
解决方案
不知道这是否可行,代码进一步说明我所说的潜在解决方案。
const fs = require('fs');
const path = 'src/index.js';
const config = [
{
input: 'page.js',
output: [
{
file: 'dist/esm/page.esm.js',
format: 'esm',
},
{
file: 'dist/cjs/page.js',
format: 'cjs',
},
],
plugins: [
// ...
],
}];
const determineFileExistsForConfig = () => {
try {
// if index exists, add to the config
if (fs.existsSync(path)) {
config.push({
input: 'src/index.js',
output: [
{
file: 'dist/esm/index.esm.js',
format: 'esm',
},
{
file: 'dist/cjs/index.js',
format: 'cjs',
},
],
plugins: [
// ...
],
});
}
} catch(err) {
return config;
}
}
const finalConfig = determineFileExistsForConfig();
export default finalConfig;
推荐阅读
- elasticsearch - 从 Http URL 读取 filebeat 配置?
- macos - Ctrl+6 不编辑在 macOS 上终端中运行的 Vim 中的备用缓冲区
- python-3.x - 如何获得 H2o 深度学习多项式模型的准确性?
- node.js - 回调作为 post 方法
- ssl - Kubernetes Haproxy Ingress + Nginx 作为后端 Https
- java - 为什么列出 pksc11-tool 七个对象但 Java Keystore 只有一个
- python - DJANGO 通用视图找不到属性“as_view”
- java - 在 intellij 项目之间重构/移动 java 包
- javascript - 根据 setInterval 值将 div 增长到 100%
- php - 在命令行 PHP-CLI 中重新加载 PHP 文件