强制使用特定的tsconfig文件

问题描述 投票:0回答:1

该项目是使用lerna工具开发的。每个程序包都有自己的tsconfig文件。

packages
 - Badge
   - ...
   -tsconfig.json
 - Button
   - ...
   -tsconfig.json
tsconfig.json

[每当我尝试创建组件包时,它都会引发错误'rootDir' is expected to contain all source files。我理解该错误是因为我正在尝试创建两个文件的捆绑包,其中一个来自徽章i:e badge.ts,另一个来自按钮i:e button.ts和tsconfig各自的子文件夹都有rootDir。我的意思是按钮的rootDir仅指向按钮源代码,并且不包括徽章源代码,反之亦然。

是否有任何方法可以超越tsconfig。我的意思是仅使用外部tsconfig,而不使用子目录tsconfig

Badge tsconfig

{
  "compilerOptions": {
    "outDir": "./dist",
    "rootDir": "./src",
    "declarationDir": "./dist/types",
  },
  "extends": "../../tsconfig"
}

outer tsconfig

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
      "esnext",
      "dom",
      "dom.iterable"
    ],
    "removeComments": true,
    "declaration": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": [
    "**/**/*.spec.ts",
    "dist/",
    "dist-es2015/"
  ]
}

webpack.config.js

const path = require('path');

module.exports = {
  entry: ['./packages/badge/src/index.ts', './packages/button/src/index.ts'],
  module: {
    rules: [
      {
        test: /\.ts?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

:如果我只有一个条目文件,即entry: './packages/badge/src/index.ts',则创建该包时不会出错。但是,来自两个不同文件夹的两个文件路径会引发错误'rootDir' is expected to contain all source files

webpack tsconfig
1个回答
0
投票

当然,请看看tsconfig-paths-webpack-pluginhttps://www.npmjs.com/package/tsconfig-paths-webpack-plugin

© www.soinside.com 2019 - 2024. All rights reserved.