【问题标题】:Bollup output is hashed and contains exportsBolup 输出经过哈希处理并包含导出
【发布时间】:2021-07-06 15:35:01
【问题描述】:

我有这个使用后台脚本的 chrome 扩展。这个后台脚本是用 typescript 编写的,到目前为止,我能够使用 tscbrowserify 创建单个文件/包。在我需要 socker.io-client 之前,这工作得很好。有了那个 browerify 就不能再做这项工作了,所以我找了些别的东西,然后找到了 Rollup。

我现在有一些东西正在运行,但是当我尝试加载 chrome 扩展时,它给了我一个错误:

Uncaught ReferenceError: exports is not defined

我希望它也能替换那些(我猜)并内联所有依赖项。

所以,这是我的 rollup.config.js 文件

import merge from 'deepmerge';
import { createBasicConfig } from '@open-wc/building-rollup';

const baseConfig = createBasicConfig();

export default merge(baseConfig, {
    input: './out-tsc/src/background/background.js',
    output: {
        dir: 'dist',
    }
});

还有我的 tsconfig.json

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "lib": ["es2017", "dom"],
    "strict": true,
    "esModuleInterop": false,
    "outDir": "out-tsc",
    "rootDir": "./"
  },
  "include": [
    "./src/background/background.ts",
    "./src/background/**/*.ts"
  ]
}

我用来编译后台脚本的命令是:

$> tsc --build ./tsconfig-background.json && rollup -c rollup.config.js

有什么建议可以解决exports 错误吗?

【问题讨论】:

    标签: typescript rollup


    【解决方案1】:

    我刚刚找到了一个非常基本的 Webpack 示例,它完全符合我的需要。虽然这不是我问题的答案,但它解决了我的问题,也许它也可以帮助其他人。下面是 Webpack 代码:

    const path = require('path');
    module.exports = {
        entry: "./src/background/background.ts",
        output: {
            filename: "background.js",
            path: path.resolve(__dirname, 'dist')
        },
        resolve: {
            extensions: [".webpack.js", ".web.js", ".ts", ".js"]
        },
        module: {
            rules: [{ test: /\.ts$/, loader: "ts-loader" }]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-26
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2013-11-23
      相关资源
      最近更新 更多