以下是关于如何指定
configFile
的说明(自2017年12月Webpack 3.10.0版本开始,原名为
configFileName
,正如Frank所述)。
Webpack配置
注意:自
版本2以来,Webpack已经使用
module.rules
而不是
module.loaders
,并且已经弃用了查询参数,转而使用
options
对象。
module.exports = {
entry: {
"./build/bundle" : "./src/startup/Entry.ts"
},
output: {
filename: '[name].js',
libraryTarget: 'this'
},
devtool: 'source-map',
resolve: {
modules: [".", "node_modules"],
extensions: [".js", ".webpack.js", ".web.js", ".d.ts", ".ts", ".tsx"]
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: [/node_modules/],
loader: "ts-loader",
options: {
configFile: "webpack_configs/tsconfig.webpack.json"
}
}
]
},
plugins: []
};
目录结构
我的目录结构的根目录如下:
webpack.config.js
webpack_configs/tsconfig.webpack.json
tsconfig.json
package.json
src/*
test/*
node_modules/*
build/*
...其中*
表示多个文件。
Typescript配置
tsconfig.webpack.json
本身只是通过排除test
文件夹来扩展我的通用tsconfig.json
:
{
"extends": "../tsconfig",
"exclude": [
"node_modules",
"test"
]
}
...但是你不需要两个webpack配置文件才能从configFile
设置中受益;你可以简单地使用它来将目标定位到自定义位置的单一tsconfig.json
。