I am trying to create a package using typescript, rollup and react, the problem is when I build the package, in the generated sourcemap, it will include ../src/components/* files that does not exist in built folder (it includes path to actual src folder), and then it causes problems when you install the package. how can I remove these pathes or include src folder inside build folder? here are my config files:
tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationDir": "types",
"module": "ESNext",
"target": "es5" ,
"lib": ["es6", "dom", "es2016", "es2017"],
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"emitDeclarationOnly": true ,
"esModuleInterop": true ,
"strict": true ,
"forceConsistentCasingInFileNames": true
}
}
tsconfig.build.json:
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "src/stories/**"]
}
and rollup.config.js:
import resolve from "@rollup/plugin-node-resolve";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import postcss from "rollup-plugin-postcss";
import { terser } from "rollup-plugin-terser";
const pkg = require("./package.json");
const inputFileName = "src/index.ts";
const moduleName = pkg.name.replace(/^@.*\//, "");
const author = pkg.author;
const banner = `
/**
* @license
* author: ${author}
* ${moduleName}.js v${pkg.version}
* Released under the ${pkg.license} license.
*/
`;
export default [
{
input: inputFileName,
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: "true",
banner
},
{
file: pkg.module,
format: "esm",
sourcemap: "true",
banner
}
],
plugins: [peerDepsExternal(), resolve(), commonjs(), typescript({ tsconfig: "./tsconfig.build.json" }), postcss(), terser()]
},
{
input: "dist/types/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
plugins: [dts()],
external: [/\.css$/]
}
];