为什么Webpack直接导入webpack.config.babel.js? [英] How come, Webpack directly imports webpack.config.babel.js?

查看:498
本文介绍了为什么Webpack直接导入webpack.config.babel.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个相当大的ReactJS项目的新手.在顶层,它没有没有具有通常的webpack.config.js,而只有一个"webpack.config.babel.js".我可以在运行时验证这一点确实得到了使用

I am new on a pretty big ReactJS project. On top level, it does not have the usual webpack.config.js, but only a `webpack.config.babel.js'. That this one does indeed get used I can verify, when running

> webpack

被调用(通过npm run使用NODE_ENV = development和WEBPACK_CONFIG =server_dev²,但这没什么大不了的.)

gets called (through npm run with NODE_ENV=development and WEBPACK_CONFIG=server_dev², but that should not matter much).

a)如果我删除了babel-config,我将得到一个正当的抱怨,即:

a) If I remove that babel-config, I get a rightful complaint, that:

当前配置文件可以命名为"webpack.config.js" 目录.

A configuration file could be named 'webpack.config.js' in the current directory.

b)如果相反,我添加了我自己的几乎没有做的东西" webpack.config.js,该确确实实是规则"(不再使用webpack.config.babel.js).

b) If, instead, I add my own do-almost-nothing webpack.config.js that one indeed "rules" (with webpack.config.babel.js no longer being used).

因此,很显然,如果缺少此文件,则会启动一个无敌"默认值webpack.config.js.再说一遍,显然吗?此默认配置以某种方式迎合了webpack配置吗?通过什么方式?通过安装那些节点模块?

So, apparently, there's an "invible" default webpack.config.js that kicks in, if this file is missing. And again, apparently?, this default configuration somehow caters to the webpack-configuration? By what? By virtue of having those node-modules installed?

或者.babelrc是要打包到Webpack的标记文件吗?

Or is .babelrc a marker file of sorts to webpack?

有趣的是,这个项目 preact-www 项目具有相同的含义. (也不是原始的webpack配置,而是webpack的风格).所以他们知道一些,我不知道...

Interestingly, this project, preact-www project has the same thing. (nor original webpack config, but the webpack flavour). So they know something, I don't...

推荐答案

Webpack使用 interpret 加载配置文件.它需要第一个文件,其基本名称为 webpack.configwebpackfile 任何扩展名interpret都知道.此外,它优先于 .js 文件.

Webpack uses interpret to load configuration file. It takes first file with basename webpack.config or webpackfile and any extension interpret knows. Additionally, it gives priority to .js files.

找到配置后,它注册相应的编译器需要配置.特别是在.babel.js的情况下,它会尝试要求

After having found the config, it registers corresponding compiler and requires the config. Particularly in case of .babel.js, it tries to require these three modules one after another until one of them is found. If it succeeds, babel basically hooks into requiring files.

这篇关于为什么Webpack直接导入webpack.config.babel.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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