Webpack require.context不适用于Path.resolve

时间:2019-02-26 04:03:28

标签: javascript webpack

webpack.config.js

"use strict";
const Path = require("path");
const resolvePath = (...paths) => Path.resolve(__dirname, ...paths);

module.exports = {
  entry: {
    data: "./src/data/index.ts" // resolvePath("src", "data", "index.ts") does not work
  }
  /** more **/
}

index.ts

const req = require.context("./yaml", true, /\.ya?ml$/i);
req.keys().forEach((key: any) => req(key));

使用"./src/data/index.ts"resolvePath("src", "data", "index.ts")编译代码。但是只有"./src/data/index.ts"包含YAML文件。 YAML文件位于./src/data/yaml

Path.resolverequire.context有何影响?如果我想使用Path.resolve,应该如何写正确的require.context

0 个答案:

没有答案