2016-12-20 11 views
1

저는 js와 ts 파일을 모두 가지고있는 프로젝트에서 일하고 있습니다. 그것들은 하나의 번들 파일로 합쳐지기로되어 있습니다.typescript와 함께 javascript를 하나의 번들로 컴파일하는 방법은 무엇입니까?

나는 꿀꺽 꿀꺽 - 타이프 라이터를 사용하고 있는데 내 구성은 다음과 같습니다 다음 configutation은 JS 파일을 포함 할 때

, 그것은 코드 번들을 생성
  gulp.src(cfg.ts_src) 
        .pipe(sourcemaps.init()) 
        .pipe(typescript({ 
         allowJs: true, 
         declaration: false, 
         diagnostics: false, 
         emitDecoratorMetadata: true, 
         experimentalDecorators: true, 
         module: "system", 
         moduleResolution: "classic", 
         noImplicitAny: true, 
         outFile: "./" + cfg.file, 
         preserveConstEnums: true, 
         pretty: true, 
         removeComments: true, 
         rootDir: "./static/" + cfg.dest, 
         target: "es5", 
        })) 
       .pipe(sourcemaps.write('.', { sourceRoot: "/static/", includeContent: false })) 

내가 가진 문제가된다. 그러나 구성에 js 및 ts 파일이 모두있는 경우 typescript는 javascript 파일을 무시하고 ts 파일 만 컴파일합니다.

js 및 ts 파일의 코드가 포함되어 있고 ts 파일의 소스 맵을 여전히 가지고있는 번들을 만들 수 있습니까?

+0

먼저 모든 TS 파일을 컴파일하고 temp dir에 넣은 다음 다른 모든 js 파일과 함께 모든 파일을 묶어보십시오. –

+0

나중에 타이프 스크립트 소스 맵을 사용할 수 있습니까? – gemrey

+0

그냥 모든 파일들로 최종 디렉토리에 복사하십시오. –

답변

0

먼저 모든 TS 파일을 컴파일하고 임시 디렉토리에 넣은 다음 모든 파일을 다른 모든 JS 파일과 함께 묶어보십시오. 또한 모든 원본 맵 파일을 최종 디렉토리에 복사하십시오.

+1

그게하고 작동합니까, 때로는 그것을하는 가장 간단한 방법은 최고입니다! – gemrey

0

gulp-typescript의 이전 버전을 사용하고있는 것 같습니다. 어쩌면 이것이 문제일까요?

gulp.task('build.js.dev',() => 
{ 
    var tsProject = ts.createProject('tsconfig.json', { 
     typescript: require('typescript') 
    }); 

    var tsResult = tsProject.src() 
     .pipe(sourcemaps.init()) 
     .pipe(tsProject()); 

    return merge([ 
     //Write definitions 
     //tsResult.dts.pipe(gulp.dest(TEMP_TARGET_FOLDER)), 
     //Write compiled js 
     tsResult.js.pipe(sourcemaps.write(
      ".", 
      { 
       includeContent: true, 
       sourceRoot: __dirname + "/dist" 
      })).pipe(gulp.dest(TEMP_TARGET_FOLDER))]); 
}); 

참고 부분 : 당신은 더 많은 샘플에 대한 꿀꺽 - 타이프 문서를 참조 할 수 있습니다 tsResult.js.pipe(sourcemaps.write(

다음은 나를 위해 작동 및 컴파일 된 TS +지도 및 원료 JS 모두를 방출하는 작업이다.

tsconfig은 옵션에 매우 유사합니다

{ 
"compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "moduleResolution": "node", 
    "module": "commonjs", 
    "target": "es6", 
    "sourceMap": true, 
    "outDir": "dist", 
    "declaration": false, 
    "allowJs": true, 
    "jsx": "react", 
    "forceConsistentCasingInFileNames": true, 
    "types": [ 
     "node", 
     "jasmine" 
    ] 
}, 
"exclude": [ 
    "./node_modules", 
    "./dist", 
    "./.vscode" 
] 
} 

희망이 도움이됩니다.

+0

최신 버전을 사용하고 있습니다 만, 아마도 그것을 구성하는 오래된 방법 일 것입니다. 하나의 파일로 컴파일하려고합니다. 내가 볼 수있는 것과 다릅니다. 하지만 지금은 해결했습니다. – gemrey

관련 문제