@gamecreator/tscompile
v0.0.4
Published
处理ts源文件排序问题。
Downloads
14
Readme
@gamecreator/tscompile
处理ts源文件排序问题。
访问
npm i @gamecreator/tscompile
如何使用
node.js
安装
npm i @gamecreator/tscompile
使用
// const { compile } = require('./');
const { compile } = require('@gamecreator/tscompile');
const tsconfig = `
{
"compilerOptions": {
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"outFile": "dist/index.js"
},
"files": [
"src/index.ts",
"src/AA.ts",
"src/A.ts"
]
}
`;
const files = {
'src/index.ts': `const aa = new AA();console.log(aa);`,
'src/AA.ts': `class AA extends A{
aa = 1;
}`,
'src/A.ts': `class A {
a = 1;
}`
};
const result = tscompile.compile(tsconfig, files);
console.log(`输出结果`, result);
console.log(`输出文件`, result.outputs);
console.log(`源码排序结果`, result.sortedFileNames);
浏览器
https://unpkg.com/@gamecreator/[email protected]/index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/lib/typescriptServices.js"></script>
<script src="https://unpkg.com/@gamecreator/[email protected]/dist/index.js"></script>
</head>
<body>
<script>
const tsconfig = `
{
"compilerOptions": {
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"outFile": "dist/index.js"
},
"files": [
"src/index.ts",
"src/AA.ts",
"src/A.ts"
]
}
`;
const files = {
'src/index.ts': `const aa = new AA();console.log(aa);`,
'src/AA.ts': `class AA extends A{
aa = 1;
}`,
'src/A.ts': `class A {
a = 1;
}`
};
const result = tscompile.compile(tsconfig, files);
console.log(`输出结果`, result);
console.log(`输出文件`, result.outputs);
console.log(`源码排序结果`, result.sortedFileNames);
</script>
</body>
</html>
参考
- https://github.com/microsoft/TypeScript
- https://github.com/domchen/typescript-plus
- https://www.typescriptlang.org/play