如何忽略Webpack中找不到的模块?

时间:2018-07-03 12:45:00

标签: webpack jupyter-notebook

我正在尝试为Jupyter Notebooks构建扩展,并希望使用webpack和babel将我的扩展分为多个文件,然后babel能够用Ecmascript编写。

为jupyter笔记本编写扩展名的标准模板如下:

 define([
     ...List of Jupyter Plugins...
 ], function(){

     ...CUSTOM Extension Code...
 })

方法define允许我们列出扩展所需的不同的依赖Jupyter模块,并且在运行时jupyter注入所有依赖关系。类似于requirejs的工作方式。

我面临的问题是,当我列出不同的依赖项时,webpack试图找到这些模块,并且由于扩展项目中未安装这些模块,因此会抛出未找到模块错误 >。

例如,我在主脚本中写了以下内容:

define([
    'base/js/namespace',
    'base/js/events',
    'base/js/utils',
    'notebook/js/codecell',
], function (
    requirejs,
    $,
    Jupyter,
    events,
    utils,
    codecell
) {
    "use strict";
    console.log('Hello World 2')

})

Webpack引发以下错误:

ERROR in ./src/main.js
Module not found: Error: Can't resolve 'base/js/events' in '/home/arjunc/app/nbextension-variable-explorer/src'
 @ ./src/main.js 5:0-9:2

ERROR in ./src/main.js
Module not found: Error: Can't resolve 'base/js/namespace' in '/home/arjunc/app/nbextension-variable-explorer/src'
 @ ./src/main.js 5:0-9:2

ERROR in ./src/main.js
Module not found: Error: Can't resolve 'base/js/utils' in '/home/arjunc/app/nbextension-variable-explorer/src'
 @ ./src/main.js 5:0-9:2

ERROR in ./src/main.js
Module not found: Error: Can't resolve 'notebook/js/codecell' in '/home/arjunc/app/nbextension-variable-explorer/src'
 @ ./src/main.js 5:0-9:2

转录和编译的文件如下:

 /***/ "./src/main.js":
/*!*********************!*\
  !*** ./src/main.js ***!
  \*********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;

!(__WEBPACK_AMD_DEFINE_ARRAY__ = [!(function webpackMissingModule() { var e = new Error("Cannot find module 'base/js/namespace'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()), !(function webpackMissingModule() { var e = new Error("Cannot find module 'base/js/events'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()), !(function webpackMissingModule() { var e = new Error("Cannot find module 'base/js/utils'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()), !(function webpackMissingModule() { var e = new Error("Cannot find module 'notebook/js/codecell'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())], __WEBPACK_AMD_DEFINE_RESULT__ = (function (requirejs, $, Jupyter, events, utils, codecell) {
    "use strict";

    console.log('Hello World 2');
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
                __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));

/***/ })

/******/ });
//# sourceMappingURL=main.js.

方法define已替换为!(__WEBPACK_AMD_DEFINE_ARRAY__ = [!(function webpackMissingModule(),其中列出了一系列错误,指出未找到模块。

define似乎是webpack的一种特殊方法。

如何忽略找不到的模块?如何“停用”特殊方法定义?

0 个答案:

没有答案