简体   繁体   English

迁移大型Typescript应用程序以使用Webpack

[英]Migrate giant Typescript application to use webpack

I have a giant Typescript application (~700 files) that uses gulp to basically concat all the files then compile into ES5. 我有一个巨大的Typescript应用程序(约700个文件),该应用程序使用gulp基本上连接了所有文件,然后编译为ES5。

Simplified example: 简化示例:

gulp.task(
'ts',
function () {
    var tsResult = gulp.src(ts_glob, { base: './js' })
        .pipe(sourcemaps.init())
        .pipe(tsProject());

    return tsResult.js
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('./'))
});

I want to start using some of Webpack's functionality and take advantage of modular javascript using import, but I can't find a way to "baby step" this process. 我想开始使用Webpack的某些功能,并通过导入使用模块化javascript,但是我找不到找到“婴儿”的方法。 As soon as use import that file's code is no longer available to the rest of the gulp based code. 一旦使用import,该文件的代码将不再对其他基于gulp的代码可用。

This may not even be a webpack problem really. 这实际上可能甚至不是webpack的问题。 If I could just get away from globbing all the files into one giant file and start using import that would be a huge win. 如果我可以避免将所有文件都放到一个大文件中并开始使用import,那将是一个巨大的胜利。

Is there anyway to piece meal this together so that I don't have to overhaul the whole app at one time? 无论如何,有没有一起做这件事,这样我就不必一次检查整个应用程序了?

Always think of the answer after I ask, and it's so simple 我问完之后,总是想想答案,这很简单

  • Create a second project and move some files to the new project. 创建第二个项目并将一些文件移到新项目。
  • Give it an angular module name like 'project.new' 给它一个有角模块名称,例如“ project.new”
  • Bundled that up with webpack as a UMD library. 将其与webpack捆绑在一起作为UMD库。
  • Reference that file in index.html of the old project. 在旧项目的index.html中引用该文件。
  • Add 'project.new' as a dependency in the old project ex: angular.module('project', ['project.new']); 在旧项目中添加“ project.new”作为依赖项,例如: angular.module('project', ['project.new']);
  • In old project either modify ts_glob to ignore the files I've moved or just delete them altogether. 在旧项目中,要么修改ts_glob以忽略我已移动的文件,要么将它们全部删除。

Now you can just move one section or file at a time. 现在,您一次只能移动一个部分或文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM