1

My Rollup Config worked in Rollup version 2. I try to migrate the rollup package to Version 3.15.0. Rollup claims that i need the output.dir option instead of using output.file. How can i achieve the same behaviour with using the output.dir option.

Problems with rollupjs configuration this post doesnt really help me.

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()],
    },
];

I tried to split the output object:


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

Since the "inlineDynamicsInports" is deprecated this is not an option

GoldJns
  • 21
  • 4

1 Answers1

0

Update: this config works for me now, i changed the json plugin import (require syntax is not recommended). I also changed the file extension from js to mjs. I decided to stay at rollup version 2, because the version 3 has caused a lot of problems/isnt really stable yet

My rollupplugin versions in case you need them:

"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/**'],
        },
    },
];
GoldJns
  • 21
  • 4