如何在Babel和Webpack浏览器中使用Typescript
我正在尝试使用以下体系结构在浏览器中使用Typescript: 但使用此命令时,导入/导出不起作用: tsc&babel构建ts-d库&webpack--config webpack.config.js 在./lib/index.js模块中找不到错误:错误:无法解析“index” 在'C:\Users\aurel\Desktop\Platformer\lib'中 在./lib/index.js模块中找不到错误:错误:无法解析“文件” 在'C:\Users\aurel\Desktop\Platformer\lib'中 index.html:如何在Babel和Webpack浏览器中使用Typescript,typescript,webpack,ecmascript-6,browser,babeljs,Typescript,Webpack,Ecmascript 6,Browser,Babeljs,我正在尝试使用以下体系结构在浏览器中使用Typescript: 但使用此命令时,导入/导出不起作用: tsc&babel构建ts-d库&webpack--config webpack.config.js 在./lib/index.js模块中找不到错误:错误:无法解析“index” 在'C:\Users\aurel\Desktop\Platformer\lib'中 在./lib/index.js模块中找不到错误:错误:无法解析“文件” 在'C:\Users\aurel\Desktop\Platfo
<script src="dist/bundle.js"></script>
file.ts
export const file = "test";
import { index } from 'index';
console.log(index)
webpack.config.js
const glob = require("glob");
module.exports = {
entry: {
js: glob.sync("./lib/**/*.js"),
},
output: {
filename: 'bundle.js',
path: __dirname + '/dist',
},
};
tsconfig.json
"target": "es6",
"module": "amd",
"outDir": "./build-ts",
你有什么想法吗?我不知道该怎么做,提前谢谢 您的导入应该是相对的,而不是绝对的:
export const index = "test";
import { file } from './file';
console.log(file)
默认情况下,将在node_modules目录中搜索绝对导入。此命令失败时,/lib目录中有什么?是否有index.js或file.js文件?lib目录包含我的babel文件(index.js和file.js)Dovakeidy,而不是感谢我编辑我的答案,你应该批准或投票。谢谢天哪!谢谢,我不知道我怎么没看到!
export const index = "test";
import { file } from './file';
console.log(file)
export const file = "test";
import { index } from './index';
console.log(index)