使用requirejs
时,我这样做:
require.config({
baseUrl: "scripts"
});
console.log("Starting!");
require(["A", "B", "C"], mainFunction);
我在Google上搜索如何设置Webpack的基本路径。我找到了resolve.root
。然而,这不起作用:
$ node run_with_node.js
D:\node_modules\webpack\lib\webpack.js:19
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
^
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.resolve has an unknown property 'root'. These properties are valid:
object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
at webpack (D:\node_modules\webpack\lib\webpack.js:19:9)
at Object.<anonymous> (D:\web\voxnap\run_with_node.js:9:18)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)
at startup (bootstrap_node.js:146:9)
我也尝试使用resolve.modules
,但如果我这样做,Webpack就找不到babeljs的内部模块。
Error: Cannot find module "babel-runtime/helpers/typeof"
那么如何正确添加包含我脚本的目录?
答案 0 :(得分:1)
您已查看了webpack的文档1. Webpack 2已删除resolve.root
并将其统一到resolve.modules
,如官方webpack 2+文档的Migration Guide所示
resolve.modules
的默认值为["node_modules"]
,如果您想保持常规模块分辨率,则还必须包含它。
resolve: {
modules: [
path.resolve(__dirname, "scripts"),
"node_modules"
]
}