Javascript 在webpack 2条目中指定完整的子目录
我有一个webpack 2配置,如下所示:Javascript 在webpack 2条目中指定完整的子目录,javascript,typescript,webpack,webpack-2,Javascript,Typescript,Webpack,Webpack 2,我有一个webpack 2配置,如下所示: module.exports = { context: __dirname, entry: [ "./app.ts", "./tab.ts", "./client/clientService.ts", "./client/clientSearchComponent.ts", "./infrastructure/messageComponent.ts",
module.exports = {
context: __dirname,
entry: [
"./app.ts",
"./tab.ts",
"./client/clientService.ts",
"./client/clientSearchComponent.ts",
"./infrastructure/messageComponent.ts",
"./infrastructure/typeaheadComponent.ts",
"./url.ts"],
output: {
filename: "./wwwroot/js/admin/admin.js"
},
devtool: "source-map",
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' }
]
}
};
这将导入到一个gulp任务中,如下所示
gulp.task("admin:js",
function (done) {
var configuration = require(path.join(__dirname, config.js, "admin/webpack.config.js").toString());
webpack(configuration).run(reportWebpackResults(done));
});
我发现我必须在条目[…]中指定每个组件
如何指定glob,它们似乎不是开箱即用的
entry: [
"./client/**/*.ts", // module not found...
您可以使用像这样的全局库globle.find
返回一个文件数组。因此,您可以将其用作条目:
entry: globule.find("./client/**/*.ts")
如果还想包括其他入口点,可以通过分散返回的数组来组合它们:
entry: [
'./other/entry.js'
...globule.find("./client/**/*.ts")
]
或使用组合阵列的任何其他方式(例如)
或者,您可以使用单个条目,在问题中所示的帮助下导入所需的所有内容
const req = require.context('./client/', true, /\.ts$/);
req.keys().forEach(req);