【问题标题】:Rollup and typescript bundle is without editor code completion and jump to declarationRollup 和 typescript 包没有编辑器代码完成并跳转到声明
【发布时间】:2020-06-12 19:45:20
【问题描述】:

对捆绑非常陌生。我的团队习惯于编码完成,并能够在他们的编辑器(VSCode)中使用command + click 跳转到相应组件的类型声明文件。

但是生成的捆绑包没有这种行为......我不知道如何在这里形成,或者我错过了什么。这些功能对我的团队非常重要。任何帮助表示赞赏????

版本

  • 打字稿:3.7.5
  • 汇总:1.31.0
  • rollup-plugin-typescript2: 0.26.0

rollup.config.js

import babel from 'rollup-plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import svgr from '@svgr/rollup';
import url from '@rollup/plugin-url';
import json from '@rollup/plugin-json';
import external from 'rollup-plugin-peer-deps-external';
import includePaths from 'rollup-plugin-includepaths';

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

export default {
  cache: false,
  input: 'src/index.ts',
  output: { file: pkg.module, format: 'esm' },
  plugins: [
    external({
      preferBuiltins: false,
    }),
    babel({
      exclude: /node_modules/,
      plugins: ['external-helpers'],
      externalHelpers: true, 
    }),
    json(),
    resolve(),
    svgr({
      ref: true,
      svgo: false,
    }),
    typescript({
      clean: true,
      typescript: require('typescript'),
    }),
    url(),
    includePaths({
      paths: ['src'],
    }),
    commonjs({
      namedExports: {
        'prop-types': [
          'oneOfType',
          'func',
          'shape',
          'any',
          'number',
          'object',
          'bool',
          'string',
        ],
      },
    }),
  ],
};

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "src",
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "es6",
    "moduleResolution": "node",
    "noEmit": true,
    "noErrorTruncation": true,
    "outDir": "./dist",
    "skipLibCheck": true,
    "strict": true,
    "target": "es5",
    "rootDir": "src"
  },
  "include": ["src"],
  "exclude": ["storybook", "dist"]
}

package.json

只有相关位????

{
  "main": "dist/index.js",
  "module": "dist/index.js",
  "typings": "dist/index.d.ts",
}

【问题讨论】:

    标签: reactjs typescript types visual-studio-code rollup


    【解决方案1】:

    找到了问题 - 这是因为我使用的是绝对路径。在构建时将导入路径更改为相对导入或使用插件将绝对导入路径转换为相对导入路径可修复此问题。

    【讨论】:

    • 你用的是什么插件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多