jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

Specify custom tsconfig.json path? #790

Closed alonfai closed 4 years ago

alonfai commented 4 years ago

Current Behavior

The tool currently uses the local defined in root directory tsconfig.json.

Desired Behavior

I want to override the given config file to refer to a different tsconfig.development.json or tsconfig.release.json, which currently isn't possible. I tried import the givenrollup-plugin-typescript2 that tsdx uses and give a different tsconfig prop or tsconfigOverride property, but got an error relating to babel.


// ...tsdx.config.js

module.exports = {
  rollup(config, options) {
    return {
      ...config,
      plugins: [
        ...config.plugins,
        typescript({
          typescript: require('typescript'),
          tsconfig: 'tsconfig.development.json'
      ]
    }
  }
};

# Running in package.json script "build": "tsdx build"

// In the terminal Receiving the following error

semantic error TS2307: Cannot find module 'rollupPluginBabelHelpers.js' or its corresponding type declarations.

Suggested Solution

Need an easy way to overwrite the given typescript settings in the project

agilgur5 commented 4 years ago

This feature already exists, there is a --tsconfig flag for this.

Duplicate of #121 / #124


With regard to your code snippet and error message, that's happening because you added rpts2 a second time to the end of the existing plugins list (running it after the rest), and without the same settings. You have to replace the existing rpts2 and duplicate settings for modifications to work. It's non-trivial and very fragile per the warning.

alonfai commented 4 years ago

@agilgur5 Thanks for answering that. I found another issue relating to changing the output folder

I modify both the rollup output param and the tsconfig.json outDir and declarationDir to a parent folder of my project that is used for debugging my app that consumes the bundled output.

tsconfig.json

"compilerOptions": {
     "baseUrl": "./src",
      "outDir": "../../my-app/src/@scope/shared",
      "declarationDir": "../../my-app/src/@scope/shared"
      "allowJs": true,
      "alwaysStrict": true,
      "declaration": true,
      "esModuleInterop": true,
      "forceConsistentCasingInFileNames": true,
      "importHelpers": true,
      "jsx": "react",
      "lib": ["dom", "esnext"],
      "module": "esnext",
      "moduleResolution": "node",
      "noFallthroughCasesInSwitch": true,
      "noImplicitThis": true,
      "strictFunctionTypes": true,
      "strictPropertyInitialization": true,
      "strict": true,
      "allowSyntheticDefaultImports": true,
      "noUnusedParameters": false,
      "noUnusedLocals": false,
      "strictNullChecks": true,
      "noImplicitAny": false,
      "noEmit": true,
      "target": "es5",
      "sourceMap": true,
      "downlevelIteration": true
    }

tsdx.config.js


module.exports = {
  rollup(config, options) {
    return {
      ...config,
      // https://github.com/formium/tsdx/issues/213#issuecomment-540126058
      output: {
        ...config.output,
        // dir: path.join(__dirname, '../../my-app/src/@scope'),
        file: `../../my-app/src/@scope/shared/${path.basename(file)}`
      }
    }
    }
  }
};

The resulting run of tsdx build gives me the bundled esm/cjs for both development/production .js builds with the relevant typings, however I still have a dist folder under my scoped rollup project with the entry index.js file.

I attached a few pics to demonstrate the issue.

// current tsdx/rollup project with a single index.js under `shared/dist folder

Screen Shot 2020-08-10 at 4 03 13 pm

'use strict'


if (process.env.NODE_ENV === 'production') {
  module.exports = require('./shared.cjs.production.min.js')
} else {
  module.exports = require('./shared.cjs.development.js')
}

// The other project that consumes the bundled output

Screen Shot 2020-08-10 at 4 05 40 pm

agilgur5 commented 4 years ago

That is an unrelated issue so I've marked it as off-topic, please keep issues single topic, it creates confusion otherwise.

And that is also a duplicate of https://github.com/formium/tsdx/issues/351#issuecomment-657284291 ....