Webpack 和 Express - 严重依赖警告 [英] Webpack and Express - Critical Dependencies Warning

查看:26
本文介绍了Webpack 和 Express - 严重依赖警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 webpack.config.ts:

var webpack = require( 'webpack' );
var path = require( 'path' );

module.exports = {

  entry: [
    './api/bin/www.ts'
  ],
  output: {
    path: path.resolve( __dirname, './dist/api' ),
    filename: 'index.js'
  },
  module: {
    loaders: [
      { test: /.ts$/, loader: 'awesome-typescript-loader' },
      { test: /.json$/, loader: 'json-loader' }
    ]
  },
  resolve: {
    extensions: [ '', '.js', '.ts' ]
  },
  target: 'node',
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};

当我运行 webpack 时,我收到一个关于依赖项的警告:

When I run webpack I get a warning about a dependency:

WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
@ ./~/express/lib/view.js 78:29-56

我从这里开始的 express 服务器只不过是一个 Hello World 示例和 应有的功能,但我很担心这个警告.

The express server I start with this is no more than a Hello World example and functions as should but I am concerned about this warning.

我的 googlefu 没有透露任何可行的解决方案.我见过此问题的一个特定实例,但解决方案是通过不显示警告来绕过警告.

My googlefu hasn't revealed any passable solutions. I have seen one particular instance of this problem but the solutions were to bypass the warning by not showing it.

推荐答案

使用 webpack-node-externals.

Use webpack-node-externals.

const nodeExternals = require('webpack-node-externals');

{
  target: 'node',
  externals: [nodeExternals()],
}

https://www.npmjs.com/package/webpack-node-externals

这篇关于Webpack 和 Express - 严重依赖警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆