【发布时间】:2019-09-13 20:36:41
【问题描述】:
我正在尝试将旧的 typescript 项目转换为新的 vue.js 项目的库。较旧的软件包配置为使用tsconfig.json 输出到./lib/,package.json 包括我能想到的所有“这是我的库所在的位置”选项。 tsc 将旧包中的所有内容编译为lib/,npm link 用于将包连接在一起。
我的问题是,无论我尝试了什么,我似乎都无法从我的导入中删除 lib/ 段,例如 import { baz } from "older/common/thing" 而不是 import { baz } from "older/lib/common/thing"。我应该忍受它吗?或者我应该为更漂亮的导入做些什么?
package.json(部分)
{
"main": "./lib/index.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
}
tsconfig.json
{
"compilerOptions": {
"module": "es6",
"target": "es6",
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"removeComments": true,
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true,
"importHelpers": true,
"sourceMap": true,
"typeRoots": [
"typings",
"node_modules/@types"
],
"outDir": "./lib",
"declaration": true
},
"include": [
"app/source/**/*",
"test/**/*"
],
"exclude": [
"node_modules"
]
}
【问题讨论】:
-
我不能告诉你怎么做,但我认为这是可能的。
import被 typescript 和 webpack 使用,所以你应该告诉 typescript 和 webpack 如何解析这些模块。也许在某个地方有代码源/示例,它会更容易帮助你。
标签: typescript vue.js es6-modules