Webpack CLI silently fails when running it on a .ts file?

Viewed 131

I have a webpack.config.js file with a default entrypoint, i.e.:

module.exports = {
  entry: {
    main: path.resolve('./src/main.ts'),
  },
  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        use: ['babel-loader'],
        ...
      },
      ...
    ],
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    ...
  },
  ...
};

Running npx webpack directly builds main.ts as expected. In addition, if I pass in an input file as an argument, it can build any .js files:

npx webpack someScript.js

However, with a .ts file, it ignores the input file argument and builds the default entrypoint instead. It doesn't even show a warning.

How can I get Webpack CLI to build a .ts file?

1 Answers

To build typescript files using webpack, I think this could be the best guide. Please have a look at it and if it is not what you want, it would be better to make more clear your questions to discuss details.

https://webpack.js.org/guides/typescript/

Related