1 | const typescript = require('typescript');
|
2 | module.exports = (option)=>{
|
3 | option = option || {
|
4 | alwaysStrict:true, //是否启用严格模式
|
5 | lib:typescript.ScriptTarget.ES3, //编译库'ES3','ES5','ES2015','ES2016','ES2017','Latest'
|
6 | module:typescript.ModuleKind.ES2015, //代码生成规范'None','CommonJs','AMD','UMD','System','ES2015'
|
7 | sourceMap:true //生成map文件
|
8 | //sourceRoot:'', //源文件位置
|
9 | //inlineSourceMap:true, //在文件中嵌入map信息
|
10 | //inlineSources:true //生成源码图,需要inlineSourceMap开启
|
11 | };
|
12 |
|
13 | return {
|
14 | transform: function transform ( code, id ) {
|
15 | let transformed = typescript.transpileModule(
|
16 | code,
|
17 | {
|
18 | compilerOptions:option,
|
19 | //moduleName:"test",
|
20 | fileName:id
|
21 | }
|
22 | );
|
23 |
|
24 | return {
|
25 | // Always append an import for the helpers.
|
26 | code: transformed.outputText,
|
27 |
|
28 | // Rollup expects `map` to be an object so we must parse the string
|
29 | map: transformed.sourceMapText ? JSON.parse(transformed.sourceMapText) : null
|
30 | };
|
31 | }
|
32 | };
|
33 | }; |
\ | No newline at end of file |