reactjs 当绑定多个文件时,必须使用output.dir选项

kgqe7b3p  于 2023-05-17  发布在  React
关注(0)|答案(1)|浏览(100)

我的汇总配置在汇总版本2中工作。我尝试将汇总包迁移到版本3.15.0。Rollup声称我需要output.dir选项而不是output.file。如何使用output.dir选项实现相同的行为?
Problems with rollupjs configuration这篇文章真的帮不了我。
rollup.config.js

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';

const packageJson = require('./package.json');

export default [
    {
        external: ['react', 'react-dom'],
        input: 'src/index.ts',
        output: [
            {
                file: packageJson.main,
                format: 'cjs',
                sourcemap: true,
            },
            {
                file: packageJson.module,
                format: 'esm',
                sourcemap: true,
            },
        ],
        plugins: [resolve(), commonjs(), typescript({ tsconfig: './tsconfig.json' })],
    },
    {
        external: ['react', 'react-dom'],
        input: 'dist/esm/index.d.ts',
        output: [{ file: 'dist/index.d.ts', format: 'esm' }],
        plugins: [dts()],
    },
];

我尝试拆分输出对象:

{
        input: 'src/index.ts',
        output: 
        {
          file: packageJson.main,
          format: 'cjs',
          sourcemap: true,
         },
},
{
        input: 'src/index.ts',
        output: 
        {
          file: packageJson.module,
          format: 'esm',
          sourcemap: true,
         },
}

由于“inlineDynamicsInports”已被弃用,因此这不是一个选项

bjp0bcyl

bjp0bcyl1#

更新:这个配置现在对我有用,我改变了JSON插件导入(不推荐使用require语法)。我还将文件扩展名从js更改为mjs。我决定继续使用RollupVersion 2,因为Version 3已经造成了很多问题/还不是很稳定
我的rollupplugin版本,如果你需要他们:
“rollup”:“^2.75.7”,“rollup-plugin-dts”:“^4.2.2”,“rollup-plugin-replace”:“^2.2.0”,“@rollup/plugin-json”:“^6.0.0”,“@rollup/plugin-node-resolve”:“^15.0.1”,“@rollup/plugin-typescript”:“^8.3.3”,

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';

import packageJson from './package.json' assert { type: 'json' };

export default [
    {
        inlineDynamicImports: true,
        external: ['react-dom', 'react'],
        input: 'src/index.ts',
        output: [
            {
                file: packageJson.main,
                format: 'cjs',
                sourcemap: true,
            },
            {
                file: packageJson.module,
                format: 'esm',
                sourcemap: true,
            },
        ],
        plugins: [typescript({ tsconfig: './tsconfig.json' }), packageJson, resolve(), commonjs()],
        watch: {
            exclude: ['node_modules/**'],
        },
    },
    {
        external: ['react-dom', 'react'],
        input: 'dist/esm/index.d.ts',
        output: [{ file: 'dist/index.d.ts', format: 'esm' }],
        plugins: [dts()],
        watch: {
            exclude: ['node_modules/**'],
        },
    },
];

相关问题