Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从网页包包中排除Express view引擎_Javascript_Node.js_Express_Webpack_Bundling And Minification - Fatal编程技术网

Javascript 如何从网页包包中排除Express view引擎

Javascript 如何从网页包包中排除Express view引擎,javascript,node.js,express,webpack,bundling-and-minification,Javascript,Node.js,Express,Webpack,Bundling And Minification,我正在使用Webpack v4捆绑我的CLI应用程序。其中一个依赖项是Express,这会导致警告: WARNING in ./node_modules/express/lib/view.js 81:13-25 Critical dependency: the request of a dependency is an expression @ ./node_modules/express/lib/application.js @ ./node_modules/express/lib/exp

我正在使用Webpack v4捆绑我的CLI应用程序。其中一个依赖项是Express,这会导致警告:

WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/express/lib/application.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
来自Express内部的信息:

/**
 * Initialize a new `View` with the given `name`.
 *
 * Options:
 *
 *   - `defaultEngine` the default template engine name
 *   - `engines` template engine require() cache
 *   - `root` root path for view lookup
 *
 * @param {string} name
 * @param {object} options
 * @public
 */

function View(name, options) {
  var opts = options || {};

  this.defaultEngine = opts.defaultEngine;
  this.ext = extname(name);

  // ...

  if (!opts.engines[this.ext]) {
    // load engine
    var mod = this.ext.substr(1)
    debug('require "%s"', mod)

    // default engine export
    var fn = require(mod).__express // <-- this require is the problem
/**
*使用给定的“名称”初始化新的“视图”。
*
*选项:
*
*-`defaultEngine`默认模板引擎名称
*-`engines`模板引擎需要()缓存
*-`root`视图查找的根路径
*
*@param{string}name
*@param{object}选项
*@公众
*/
功能视图(名称、选项){
var opts=options | |{};
this.defaultEngine=opts.defaultEngine;
this.ext=extname(name);
// ...
如果(!opts.engines[this.ext]){
//负载发动机
var mod=this.ext.substr(1)
调试('需要“%s”,mod)
//默认引擎导出

var fn=require(mod)。\uu express/您可以尝试的是更改您的网页配置模块规则,以便
视图
单元使用
空加载程序

这当然会使
View
返回
null
,但如果您从未接触视图,则可能没有问题

例如

rules: [
 {
   test: require.resolve("express/view"),
   use: 'null-loader',
  },
],
查看
应用程序

this.set('view',view);
希望这里的视图为空不会引起问题


应用程序中唯一提到的
视图
是在
渲染
中,你说你不使用它。所以祈祷这不会造成任何副作用。

多年来大多数express功能都是从express中提取出来的,例如
express.static
等,因此如果你不需要模板功能e你可以绕过express而不使用它。可能你使用express的主要原因是路由逻辑,所以这个模块可能很方便->我甚至没有直接使用express,它是通过另一个依赖项使用的。真的,虽然我只是在寻找一个网页包配置修复程序,但我不想重写我的整个应用程序以避免出现网页包问题rning:-)哦,我可能有个主意,我会发布一个答案,因为它不适合发表评论。