rspack icon indicating copy to clipboard operation
rspack copied to clipboard

support analyze AMD module format

Open ahabhgk opened this issue 2 years ago • 7 comments

What problem does this feature solve?

  • #2787

What does the proposed API of configuration look like?

https://webpack.js.org/configuration/other-options/#amd

ahabhgk avatar Oct 13 '23 04:10 ahabhgk

I see that it has already been supported.

shaodahong avatar Oct 13 '23 10:10 shaodahong

Nope, I mean analyze dependencies from an AMD module and bundle its dependencies, for now Rspack only support output an AMD format library if I remember correctly

ahabhgk avatar Oct 13 '23 10:10 ahabhgk

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] avatar Dec 24 '23 11:12 stale[bot]

用systemJs应该都会遇到这个问题,因为systemJs要求引入umd模块必须提前引入amd extra来提供amd环境,在rspack中运行项目就会导致所有用到的umd模块都会因amd环境的存在而导出amd格式,rspack就报错了

sunft1996 avatar Jul 03 '24 03:07 sunft1996

I would like to contribute. May I try this?

nilptr avatar Aug 14 '24 02:08 nilptr

Hi, I have started working on this issue last weekend. After some research I realised the change is much bigger than I expected. I feel we'd better break it down into 3 stages. Smaller PRs are also easier to review. My plan is to

  1. add AMD dependencies
  2. implement AMD plugin and integrate with bundler
  3. add test cases to verify and fix bugs

So far I have finished stage 1, I will create a draft PR. We can discuss the implementation there.

I will use my branch as feature branch for stage 2 and stage 3.

nilptr avatar Aug 19 '24 14:08 nilptr

Great to hear that someone is into that @nilptr That's basically the only thing that's missing and messing the hustle free switch from webpack. We have a bunch of jquery-ui imports that don't work out of the box. Do you know how to fix it before you implement this?

olhapi avatar Sep 17 '24 12:09 olhapi

Is this the place to report AMD issues or should I open a new issue?

I'm struggling with Rspack output regarding an AMD build breaking at runtime because of Rspack including the umd wrapper from a dependency:

"../../../../../node_modules/json-logic-js/logic.js": (function (module) {
 /* globals define,module */
 /*
 Using a Universal Module Loader that should be browser, require, and AMD friendly
 http://ricostacruz.com/cheatsheets/umdjs.html
 */
 ;(function(root, factory) {
   if (typeof define === "function" && define.amd) {
     define(factory);
   } else if (true) {
     module.exports = factory();
   } else {}
 }(this, function() {
   "use strict";
   /* globals console:false */
// ... module code

Where as webpack output contains this instead (which doesn't use the global define function):

  /***/ "../../../../../node_modules/json-logic-js/logic.js":
  /*!**********************************************************!*\
    !*** ../../../../../node_modules/json-logic-js/logic.js ***!
    \**********************************************************/
  /***/ (function(module, exports, __webpack_require__) {
  
  var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/* globals define,module */
  /*
  Using a Universal Module Loader that should be browser, require, and AMD friendly
  http://ricostacruz.com/cheatsheets/umdjs.html
  */
  ;(function(root, factory) {
    if (true) {
      !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
      __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
      (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
      __WEBPACK_AMD_DEFINE_FACTORY__),
      __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
    } else {}
  }(this, function() {
    "use strict";
    /* globals console:false */

The bundle is built with output.library.type = 'amd' but the environment the bundle is loaded in uses SystemJS and it's AMD extra. As the rspack output uses global define() this breaks as SystemJS creates a System.Register module under the hood which results in the json-logic-js module being empty.

jackw avatar Nov 14 '24 16:11 jackw