网站搜索

javascript - 无法导入任何默认导出(typescript 和 rollup),只能导入命名导出

我开始了一个新的 Lit2 项目,构建自定义的网页组件,但在导入外部库时遇到了问题。我按照 Lit2 文档建议使用了项目生成器,https://open-wc.org/docs/development/generator/。

这是我的 tsconfig.json

{ "compilerOptions": { "target": "es6", "module": "esnext", "moduleResolution": "node", "noEmitOnError": true, "lib": ["es2016", "esnext", "dom"], "strict": true,

阅读更多 →

reactjs - 使用 Rollup 打包多个文件时必须使用 output.dir 选项

我的 Rollup 配置在 Rollup 版本 2 中可用。我尝试将 rollup 包迁移到版本 3.15.0。Rollup 声称我需要使用 output.dir 选项,而不是使用 output.file。我如何使用 output.dir 选项实现相同的行为。

rollupjs 配置的问题,这篇文章对我没有真正帮助。

rollup.config.js

import resolve from '@rollup/plugin-node-resolve'; import commonjs fro

阅读更多 →

svelte + rollup + typescript + tsconfig 路径:使具有 .svelte 扩展名的文件可以通过绝对路径导入

有人掌握如何让这个工作的方法吗?我正在尝试使用 tsconfig 路径从相对导入迁移到绝对导入,但在解析 *.svelte 文件时遇到了问题。

tsconfig.json:

{ "extends": "@tsconfig/svelte/tsconfig.json", "compilerOptions": { "baseUrl": ".", "lib": [ "dom", "es2020" ], "paths": { //❗ "~/*": [ "src/*" ] }, "strict": true, }, "include": [ "src/*

阅读更多 →

reactjs - 无法从 rollupOptions 或 HTML 文件自动确定入口点,并且没有明确的 optimizeDeps

在我的团队项目中,在前端部分,我们使用了 vite、react、yarn、typescript。

我将构建并部署带有前端的 Docker。

我已经成功构建了一个包含前端的 Docker 镜像,但我无法部署它。

更具体地说,只有部分部署成功。

当我在 Docker 中打开它并查看容器日志时,我看到它看起来如下。

VITE v4.3.9 ready in 247 ms ➜ Local: http://localhost:3000/ ➜ Network: http://172.17.0.4:3000/ (!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.

http://172.17.0.

阅读更多 →

typescript - 在使用 rollup 且 preserveModules: true 的情况下,以及在 monorepo 中,将 TS 类型定义与 dist 放在同一位置

我有以下使用场景:一个使用 turborepo 的单一仓库,使用 TypeScript,包含多个 turborepo 包,并且每个包都使用 rollup,设置为 preserveModules: true。

我使用 preserveModules: true 因为我希望能够独立导入每个组件、文件等。

然而,如果我有 packageA/components/Button.tsx 从 packageB/types/BaseTypes.ts 导入一个类型,那么在 packageA 内得到一个 dist

- dist - components - Button.js - packageA - components - Button.d.ts - packageB - BaseTypes.d.ts

我希望我能得到像这样的东西:

阅读更多 →

typescript - 如何配置 rollup js 打包 Node 模块的 CommonJS

我有一个简单的 TypeScript 应用程序,我在浏览器中运行它。为了打包 TypeScript 文件,我使用了 Rollup JS。

我安装了扩散软件包

npm install diffusion

并将模块导入到我的 ts 文件 app.ts 中:

import * as diffusion from 'diffusion'; diffusion.connect({/* options */});

现在,当我在浏览器中启动应用程序时,会出现以下情况:

diffusion.js:5 Uncaught ReferenceError: exports is not defined at diffusion.js:5:23

这是导致错误的那行代码:

Object.defineProperty(exports, "_

阅读更多 →

typescript - 使用 rollup 打包器进行 cypress 组件测试

我在我的单一仓库中的主要打包工具是 rollup 。我正在尝试按照此处的文档配置 Cypress 组件测试。我的 cypress.config.ts 文件如下

const INIT_FILEPATH = path.resolve(__dirname, './initCypress.js') async function startDevServer(cypressConfig: Cypress.PluginConfigOptions) { const { indexHtmlFile } = cypressConfig const loader = fs.readFileSync(INIT_FILEPATH, 'utf8') const server = express() server.use(express.static('__cypress')) server.use(express.static('cypress/support/component.

阅读更多 →

node.js - 使用绝对 TypeScript 导入的 Rollup

  • 来源:这里:https://github.com/arvigeus/roll-on-slow
  • 输出包:dist
  • 构建日志:build.log

Rollup 打包没有问题,但它会因为错误的源映射抛出一些警告(使用源映射报告错误时出错:无法解析错误的原始位置。)。问题的根源似乎是 @babel/preset-react 的 development: true(将其设置为 false 警告就消失了)。我是不是做错了什么,还是这是预期的行为?生成的代码在我看来没问题…

还有一个关于 'this' 已被重写为 'undefined' 的警告,看起来是相关的,因为当关闭该选项时它会消失。

答案#1

最后,我决定禁用 development: true

阅读更多 →

typescript - Rollup.js 不会将节点模块 discord-rpc 包含在捆绑包中。有办法做到这一点吗?

我只是在导入 discord-rpc,并且只有 main.ts。同时也在使用 rollup 插件 typescript 和 node-resolve。

main.ts 导入:

const { Client } = require("discord-rpc");

package.json 脚本和依赖项:

{

阅读更多 →

Rollup TypeScript:在 dist + cjs + es 中的声明

我正在尝试使用 rollup 打包一个带有声明 (d.ts) 文件的 TypeScript 库,并且我想输出 cjs 和 es 版本。

所以我想出了这个 rollup 配置:

const {nodeResolve} = require('@rollup/plugin-node-resolve') const nodeExternals = require('rollup-plugin-node-externals'); const json = require('@rollup/plugin-json'); const commonjs = require('@rollup/plugin-commonjs'); const typescript = require('rollup-plugin-typescript2'); const packagePlugin = require('@mpen/rollup-plugin-package'); const cleanPlugin = require('@mpen/rollup-plugin

阅读更多 →