I have 2 tsconfigs, one for my dev build and one for my prod build.
I choose the tsconfig with the -p
flag :tsc -p dev.tsconfig.json
Ts-loader is looking for a tsconfig.json file. How can I specify another filename with the ts-loader?
module.exports = { entry : __dirname + "/src/app/main.ts", output : { path : __dirname + "/dist", filename : "bundle.js" }, resolve : { extensions : ["", ".webpack.js", ".web.js", ".js", ".ts"] }, module: { loaders: [ { test: /\.ts?$/, loader: "ts" } ] } };
First, for ts-loader to produce sourcemaps, you will need to set the tsconfig.
Normally in a typescript project you have a tsconfig. json file, which is used with the tsc npm command to compile the project into javascript. With webpack however the project is compiled, without tsc being installed.
In Webpack 4 you need to specify the options into a use
object:
use: [{ loader: 'ts-loader', options: { configFile: "tsconfig.webpack.json" } }]
Complete Webpack config:
var path = require('path'); module.exports = { entry: path.resolve(__dirname, 'src') + '/index.ts', output: { path: path.resolve(__dirname, 'dist'), filename: 'your-library-name.js', }, module: { rules: [ { test: /\.ts$/, use: [{ loader: 'ts-loader', options: { configFile: "tsconfig.webpack.json" } }], exclude: /node_modules/, } ] }, mode: 'development', resolve: { extensions: ['.js', '.ts'] }, devtool: false };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With