首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何摆脱"@ Rollup /plugin-typescript: Rollup 'sourcemap‘选项必须设置为生成源映射“。警告?

如何摆脱"@ Rollup /plugin-typescript: Rollup 'sourcemap‘选项必须设置为生成源映射“。警告?
EN

Stack Overflow用户
提问于 2020-07-28 14:57:47
回答 2查看 5.4K关注 0票数 12

我每次为产品构建时都会收到这个警告。当我为生产环境构建时,我在汇总输出配置中禁用了源映射。

代码语言:javascript
复制
output: [{ dir: "...", format: "...", sourcemap: isProd ? false : true }]

我对开发和生产使用相同的tsconfig,即tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    // Output
    "target": "ESNext",
    "module": "ESNEXT",
    "sourceMap": true,
    "jsx": "react",
    "noEmit": true,
    // Compile time code checking
    "strict": true,
    // Libraries
    "lib": ["dom", "esnext"],
    // Imports
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "exclude": ["dist", "app"]
}

我知道这是查看汇总插件源代码时发出警告的原因:

代码语言:javascript
复制
/**
 * Validate that the `compilerOptions.sourceMap` option matches `outputOptions.sourcemap`.
 * @param context Rollup plugin context used to emit warnings.
 * @param compilerOptions Typescript compiler options.
 * @param outputOptions Rollup output options.
 * @param autoSetSourceMap True if the `compilerOptions.sourceMap` property was set to `true`
 * by the plugin, not the user.
 */
function validateSourceMap(context, compilerOptions, outputOptions, autoSetSourceMap) {
    if (compilerOptions.sourceMap && !outputOptions.sourcemap && !autoSetSourceMap) {
        context.warn(`@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.`);
    }
    else if (!compilerOptions.sourceMap && outputOptions.sourcemap) {
        context.warn(`@rollup/plugin-typescript: Typescript 'sourceMap' compiler option must be set to generate source maps.`);
    }
}

但我不希望增加一个tsconfig用于开发而另一个用于生产的复杂性。

什么是消除此警告的好方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-28 15:10:39

票数 2
EN

Stack Overflow用户

发布于 2021-06-09 01:23:27

在我的例子中,我使用的是带有TypeScript集成的官方Svelte starter template

在我的例子中,我不需要更改默认的由模板扩展的tsconfig (具有"sourceMap": true,);我只需要更改rollup.config.js中的output.sourcemap设置,使其与传递给typescript()插件的选项一致:

代码语言:javascript
复制
const production = !process.env.ROLLUP_WATCH;

export default {
    input: 'src/main.ts',
    output: {
//      sourcemap: true, // <-- remove
        sourcemap: !production,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        svelte({
            preprocess: sveltePreprocess({ sourceMap: !production }),
            compilerOptions: {
                dev: !production
            }
        }),
        css({ output: 'bundle.css' }),
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),
        typescript({
            sourceMap: !production,
            inlineSources: !production
        }),
        !production && serve(),
        !production && livereload('public'),
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63128597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档