2

I want to use webpack just as a typescript build tool, such that each typescript file is translated into 1 js file.

The webpack guide has this configuration:

module.exports = {
    entry: './app.tsx',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
};

question: Is it possible to modify this such that

  • each ts file translates into 1 js file and (more compliated)
  • such that no bundling occurs, and no module-webpack-boilerplate is produced?

remarks:

  1. I know I can use tsc for that, but for some reasons I would like to use webpack if possible. I simplified my scenario.

  2. There is another question sounding like the very same but the answers there do not answer anything for me: How to disable bundling in Webpack for development?

citykid
  • 9,916
  • 10
  • 55
  • 91
  • That also would help to mock dependencies in unit tests. Related question: https://stackoverflow.com/questions/57379078/how-to-mock-amd-module-dependencies-for-es6-unit-tests-with-karma-requirejs – Stefan Aug 07 '19 at 12:28

1 Answers1

2

I understand you want to forego bundling and use the loaders with Webpack. I myself had considered this to speed up my dev build process. However, I believe the question you linked to states the answer correctly: this is not currently possible. The best approach is to use the devtool property in the Webpack config to enable sourcemaps. An alternative would be to use Gulp or Grunt for the dev build if all you want is to process TypeScript.

Andrew Craswell
  • 674
  • 1
  • 6
  • 17
  • Yes, I could not find any other statement. "Web"-pack is not a dependency tracking "Web"-Packer but a js module bundler and does not let go from scripts. They think the dependency graph starts in the middle, at the script part, while this is wrong (its html) and also there are usage scenarios where there is no js at all. This is why parcel gets it right: https://parceljs.org/how_it_works.html . In addition to is config insaneness, Webpack also suffers from this fundamental design wrongness. devtool is about script again, so not solving the issue anyhow. – citykid Dec 31 '17 at 14:52