- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
看起来很微不足道的问题。我有一个使用 rollup-plugin-typescript 和 rollup-plugin-dts 的汇总 typescript 配置。我想将我所有的 d.ts 文件捆绑到一个 d.ts 文件中,而不是让它镜像我的项目结构。我遵循了一些教程,最终得到了下面的配置。
问题: dts() 正确捆绑文件,但保留原始构建结构。我的资源都没有解决这个问题。不应该删除现在过时的输入文件吗?我处理插件不好吗?
我从哪里开始:
dist/
├── index.js
├─ dts //I compile my types into here, below is my mirrored project structure
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
我想要的是:
dist/
├── index.js
├── index.d.ts //everything bundled here
不幸的是我得到了什么:
dist/
├── index.js
├─ dts //All of this is still here, it shouldn't be
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
├── index.d.ts //It bundled correctly to this additional file though
配置文件
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "dts",
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5",
"strictFunctionTypes": true
},
"include": ["src/"],
"exclude": ["node_modules", "build", "dist", "src/stories/**", "**/*.stories.ts", "**/*.test.ts", "**/*.test.tsx"]
}
汇总配置文件
import babel from 'rollup-plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
export default [
{
input: './src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
},
],
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
resolve(),
commonjs(),
external(),
terser(),
],
},
{
input: './dist/dts/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [dts()],
},
];
最佳答案
我最近也遇到了类似的问题,并且能够想出一个漂亮的解决方案,并在配置文件中添加了一些内容。我只是在你的文件中添加东西。对于解决方案,我使用了 rollup-plugin-delete包裹。基本上我们必须删除 dts
构建完成后的文件夹。
import babel from 'rollup-plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
// Added this
import del from "rollup-plugin-delete";
export default [
{
input: './src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
},
],
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
resolve(),
commonjs(),
external(),
terser(),
],
},
{
input: './dist/dts/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [
dts(),
del({ hook: "buildEnd", targets: "./dist/dts" }), //<------ New Addition
],
},
];
在
tsconfig.json
文件,它提到声明类型文件应该输出到
dts
文件夹。取决于从
index.ts
导出的类型文件,类型将在
dts/index.d.ts
中声明和导出通过 typescript 转译过程。该文件夹可能还有其他文件。使用
rollup-plugin-dts ,它结合了来自
dts/index.d.ts
的所有导出和需要的类型到单个文件定义文件
index.d.ts
在
dist
文件夹。此过程完成后,我们要删除
dts
文件。为此,我们使用
rollup-plugin-delete
插件,让我们可以访问
rollup build hooks .这里我们要删除
dts
构建过程完成后的文件夹;为此,我们使用
buildEnd Hook ,以及目标文件夹名称。这将确保
dts
一旦汇总完成捆绑,文件夹将被删除。
关于typescript - rollup-plugin-dts 留下剩余的 d.ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68922574/
以这张表为例(我们称之为BIN_TABLE): +------+------+ | A | B | +------+------+ | 0 | 0 | | 0 |
我的Rollup项目是这样的... // rollup.config.js import pkg from "./package.json"; import {getRollupServerConfi
每当我为生产而构建时,都会收到此警告。当我为生产而构建时,我在汇总输出配置中禁用了源映射。 output: [{ dir: "...", format: "...", sourcemap: isPro
1、Rollup 概述 官网地址:https://rollupjs.org/guide/en/ Rollup 是什么 我们先看看 Rollup 的作者 Rich Harr
我想使用现在可用的 vuejs3 测试版设置一个项目。我想把它编译成es模 block ,所以我不能使用webpack。 是否有可用的种子项目/指南来设置带有汇总的 vue3 以发出 es 模块包
在SQL Server中使用ROLLUP时,如何获取明细行上方的小计行? 这是您在使用 ROLLUP 时通常会得到的结果: Group Name
我在我的 repo 的某些文件中导入了一个绝对路径,并尝试将它与 rollup 捆绑在一起 我的导入,其中/api/是绝对路径: import * from '/api/myFile.js' 但是当我
我正在使用 ES6 导入并使用 Rollup 进行编译。 输出是单个捆绑文件。 可以将 Rollup 配置为生成文件对文件的转译结果吗? 这是我正在使用的当前配置,它显然会吐出一个文件。 gulp.
我对打包机和 rollup 还很陌生具体来说。在 rollup.config.js 中有条件地散列文件名的最佳方法是什么?在为生产构建时,同时保存 index.html引用新 .css和 .js散列版
我使用 group by 和 rollup 得到以下查询结果: Divison Department Section Employee Name Employee ID Hour
我有这个sql查询 Select Case When transfer.trf_type = 'c' then 'Transfer to own card' When transf
今天在这个问题上停留了一段时间,想知道有人能提出问题出在哪里吗?这是我的代码: select g.game_name, r.rental_id, sum(if(datediff(r.return_da
Mytable,其 ID 作为自动增量客户、日期和金额我想做一个汇总,将每个客户每天的金额相加我的意思是汇总按日期和客户分组我的结果应该是这样的: +---------+--------------+
我有一个 SQL 语句,它给出了工作债权人的列表。在图像中的示例中,两个债权人都属于同一份工作。所以在显示 TOTALS 的最后一行,作业数是 1,这是正确的,因为它是同一个作业。同样,表示 NotP
+----+-------+-------+ | id | style | color | +----+-------+-------+ | 1 | 1 | red | | 2 |
我正在尝试向我的 SELECT 查询中添加一些总计,但我正在努力了解为什么这不起作用: SELECT 客户,job_type,actual_value_fee FROM jo2细节 GROUP BY
下面是我正在写的查询,但由于某种原因,它在“ROLLUP”一词之后给我一个语法错误,红色的小波浪线在汇总后的“(”下面。 SELECT building, room_number, time_slot
我想将一个 .js 文件与 rollup 捆绑在一起,其中只有一个类定义。但汇总仅创建一个空的捆绑文件。当我在类定义之外添加一些代码时,这种情况会发生变化。这将创建一个空包: class MyElem
这是我的例子(mysql Ver 14.14 Distrib 5.7.21,适用于 Win64 (x86_64)) DROP TABLE IF EXISTS t_tt; CREATE TEMPORAR
当按多个字段分组时执行 WITH ROLLUP,MySQL 返回每个组的汇总行,以及总体摘要: CREATE TABLE test (name VARCHAR(50), number TINYINT)
我是一名优秀的程序员,十分优秀!