如何在带有Babel和Webpack的浏览器中使用Typescript

问题描述 投票:0回答:1

我正在尝试通过使用以下体系结构在浏览器中使用Typescript:Typescript in browser architecture

但是当我使用此命令时,导入/导出不起作用:

tsc && babel build-ts -d lib && 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:

<script src="dist/bundle.js"></script>

index.ts

export const index = "test";
import { file } from 'file';

console.log(file)

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)
export const file = "test"; import { index } from './index'; console.log(index)

默认情况下,将在node_modules目录中搜索绝对导入。

typescript webpack ecmascript-6 browser babel
1个回答
0
投票
export const file = "test"; import { index } from './index'; console.log(index)
© www.soinside.com 2019 - 2024. All rights reserved.