【发布时间】:2022-01-16 08:42:01
【问题描述】:
如何使用 webpack 不同的入口文件/配置在第三部分包(例如vendor/ 子目录)中组织具有自己依赖关系的 JS 可重用组件?
说明:
我有以下带有入口点和组件的结构
app/
assets/
index.js
package.json
webpack.config.js
vendor/
my-utils-bundle/
assets/
components/
MyMath.js
package.json
webpack.config.js
在我的可包含在不同的入口文件/webpack 配置中 MyMath.js 组件中有node_modules/ 对包的依赖,例如mathjs 带有以下行:
import { pi, pow, round, sqrt } from 'mathjs'
....some code below...
附: mathjs 这个包中提供的依赖包 (vendor/my-utils-bundle/package.json)
然后当我运行yarn dev 在app/assets/index.js 中编译我的资产时,出现以下错误:
"./vendor/my-utils-bundle/assets/components/MyMath.js" contains a reference to the file "mathjs".
This file can not be found, please check it for typos or update it if the file got moved.
问题:
如何在app/assets/index.js 以及其他“捆绑包”(例如vendor/my-other-bundle)中将这个MyMath.js 组件用作可包含类?
看起来我也可以在 app/package.json 中安装这个 mathjs 依赖项,但似乎在应用程序级别我应该考虑捆绑 JS 依赖项,这听起来不是最好的解决方案。
【问题讨论】:
标签: javascript symfony webpack ecmascript-6 node-modules