Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 为文件夹中的每个文件创建单独的网页包包_Webpack_Webpack Config - Fatal编程技术网

Webpack 为文件夹中的每个文件创建单独的网页包包

Webpack 为文件夹中的每个文件创建单独的网页包包,webpack,webpack-config,Webpack,Webpack Config,我想为我的/tests目录中的每个.ts文件创建一个单独的包。 我当前手动列出所有文件: // webpack.config.js entry: { test1: "./src/tests/test1.ts", test2: "./src/tests/test2.ts", }, output: { filename: "[name].bundle.js" }, // resultes in `dist/test1.bundl

我想为我的
/tests
目录中的每个
.ts
文件创建一个单独的包。 我当前手动列出所有文件:

// webpack.config.js
entry: {
  test1: "./src/tests/test1.ts",
  test2: "./src/tests/test2.ts",
},
output: {
  filename: "[name].bundle.js"
},
// resultes in `dist/test1.bundle.js` and `dist/test2.bundle.js`
但我希望它能自动发生。我试着按照中的建议使用

也像这样(我在别处发现):

但这两种方法都不适用于我——每次只创建
main.bundle.js

可能的原因是什么

我的完整网页包配置:

const path = require("path");
const glob = require("glob");

module.exports = {
  resolve: {
    extensions: [".ts", ".js"]
  },

  mode: "development",
  entry: glob.sync("./src/tests/*.ts"),

  output: {
    path: path.resolve(__dirname, "dist"),
    libraryTarget: "commonjs",
    filename: "[name].bundle.js"
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: "babel-loader",

        options: {
          presets: [["@babel/typescript"]],
          plugins: [
            "@babel/proposal-class-properties",
            "@babel/proposal-object-rest-spread"
          ]
        }
      }
    ]
  },

  stats: { colors: true },
  externals: /k6(\/.*)?/,
  devtool: "source-map"
};

entry: glob.sync("./src/tests/*.ts")
const path = require("path");
const glob = require("glob");

module.exports = {
  resolve: {
    extensions: [".ts", ".js"]
  },

  mode: "development",
  entry: glob.sync("./src/tests/*.ts"),

  output: {
    path: path.resolve(__dirname, "dist"),
    libraryTarget: "commonjs",
    filename: "[name].bundle.js"
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: "babel-loader",

        options: {
          presets: [["@babel/typescript"]],
          plugins: [
            "@babel/proposal-class-properties",
            "@babel/proposal-object-rest-spread"
          ]
        }
      }
    ]
  },

  stats: { colors: true },
  externals: /k6(\/.*)?/,
  devtool: "source-map"
};