@feng3d/tscompile
v0.0.3
Published
处理ts源文件排序问题。
Downloads
2
Readme
@feng3d/tscompile
处理ts源文件排序问题。
访问
npm i @feng3d/tscompile
如何使用
node.js
安装
npm i @feng3d/tscompile
使用
// const { compile } = require('./');
const { compile } = require('@feng3d/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/@feng3d/[email protected]/index_single.html
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/lib/typescriptServices.js"></script>
<script src="https://unpkg.com/@feng3d/[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