7

I'm using the webpack loader ts-loader to compile typescript sourcefiles into a javascript bundle. Now I would like the individualy compiled javascript files also to be saved, as well as the bundle! I'm familliar with writing a very simple webpack plugin, but I'm not sure as to how to go about implementing this. That is: I don't know which events triggered by webpack to listen to and where to find the relevant data. Any help?

Flion
  • 10,468
  • 13
  • 48
  • 68
  • You can't use individual webpack compiled files. It might break with `Uncaught ReferenceError: __webpack_require__ is not defined` – Thaadikkaaran Dec 23 '16 at 07:16
  • But I asume ts-loader compiles ts to js with the typescript compiler first before webpack changes anything in the code like requires right? I just want those separate js files – Flion Dec 23 '16 at 14:46

1 Answers1

2

As I commented, you can't use webpack compiled individual files. It might break with Uncaught ReferenceError: __webpack_require__ is not defined.

It's better write your own loader or ask the ts-loader to provide the option to retain the transpiled source.

Or i have written a loader which can save the typescript compiled files as individual files.

you can use this loader second loader or post-loader as shown below

as a second loader:

module: {
    loaders: [{
      test: /\.ts?$/,
      loaders: ['scatter-loader', 'ts-loader']
    }]
}

or as a post-loader

module: {
    loaders: [{
      test: /\.ts?$/,
      loaders: ['ts-loader']
    }],
    postLoader: [{
      test: /\.ts?$/,
      loaders: ['scatter-loader']
    }]
}

Note: scatter-loader work is in progress.

Thaadikkaaran
  • 5,088
  • 7
  • 37
  • 59