export const file = "test";
import { index } from './index';
console.log(index)
我正在尝试通过使用以下体系结构在浏览器中使用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目录中搜索绝对导入。
export const file = "test";
import { index } from './index';
console.log(index)