最佳答案
我从 https://www.npmjs.com/package/ts-loader得到了这个配置:
Webpack.config.js:
var path = require('path');
var webpack = require('webpack');
module.exports = {
mode: "development",
devtool: "inline-source-map",
entry: "./src/Api.ts",
output: {
filename: "bundle.js"
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js"]
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: "ts-loader" }
]
}
};
./src/Api. ts:
export class Api {
...
}
但是当我运行 webpack 时,我得到:
Error: TypeScript emitted no output for Api.ts