设置我的Webpack文件的基本路径 [英] Set base paths for my files for webpack

查看:309
本文介绍了设置我的Webpack文件的基本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用requirejs时,我这样做:

require.config({
    baseUrl: "scripts"
});
console.log("Starting!");
require(["A", "B", "C"], mainFunction);

我正在搜索如何设置Webpack的基本路径.我发现 resolve.root .但是,那是行不通的:

I was googling how to set the base path for Webpack. I found resolve.root. However that just doesn't work:

$ 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中找到内部模块.

I also tried to use resolve.modules, but if I did that, Webpack couldn't find internal modules from babeljs.

Error: Cannot find module "babel-runtime/helpers/typeof"

那么如何正确添加包含我的脚本的目录?

So how to properly add a directory that contains my scripts?

推荐答案

您已经查看了webpack 1的文档.Webpack 2删除了resolve.root并将其统一为官方webpack 2+文档的迁移指南.

You've looked at the documentation for webpack 1. Webpack 2 removed resolve.root and unified it to resolve.modules, as shown in the Migration Guide of the official webpack 2+ docs.

resolve.modules的默认值为["node_modules"],如果要保持常规模块分辨率,还必须包括它.

The default value of resolve.modules is ["node_modules"] and if you want to keep the regular module resolution, you have to include it as well.

resolve: {
  modules: [
    path.resolve(__dirname, "scripts"),
    "node_modules"
  ]
}

这篇关于设置我的Webpack文件的基本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆