Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack ts-loader : change tsconfig filename

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" }         ]     } }; 
like image 811
gr3g Avatar asked Nov 04 '16 15:11

gr3g


People also ask

Does TS loader use Tsconfig?

First, for ts-loader to produce sourcemaps, you will need to set the tsconfig.

Does webpack use 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.


1 Answers

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 }; 
like image 58
mvermand Avatar answered Sep 22 '22 03:09

mvermand