簡體   English   中英

整理多個Webpack入口文件依賴

[英]Organize multiple Webpack entry file dependencies

如何使用 webpack 不同的入口文件/配置在第 3 部分捆綁包(例如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/依賴於 package 例如mathjs具有以下行:

import { pi, pow, round, sqrt } from 'mathjs'

....some code below...

PS mathjs依賴 package 在此捆綁包中提供( 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組件作為可包含的 class ?

看起來我也可以在app/package.json中安裝這個mathjs依賴項,但似乎在應用程序級別我應該考慮捆綁 JS 依賴項,這聽起來不是最好的解決方案。

這是自 Encore 推出以來一直存在的一個懸而未決的問題 甚至更早,鑒於根據bundles 的最佳實踐,不應分發第三方依賴項,並留給應用程序管理。

話雖如此,至少有一個包(foxy)試圖解決這個問題,方法是在安裝/更新包時掛接到composer命令並合並依賴項。

從它的自述文件(強調我的):

Foxy focuses solely on automation of the validation, addition, updating and deleting of the dependencies in the definition file of the asset package , while restoring the project state, as well as PHP dependencies if NPM or Yarn terminates with an error.

Foxy檢索所有 Composer 依賴項列表以將資產依賴項注入文件 package.json

[...]

鑒於 Foxy 不操縱任何資產依賴關系,更不用說版本約束,這允許 NPM 或 Yarn 解決資產依賴關系而無需任何中介

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM