Webpack无法解决节点响应依赖性

时间:2018-08-21 16:08:36

标签: javascript node.js webpack resque

我一辈子都无法弄清楚如何使webpack成功绑定第三方库节点。我正在使用webpack捆绑一个js文件并在AWS Lambda上使用。

node-resque的index.js文件包含以下require语句:

exports.Connection = require(path.join(__dirname, 'lib', 'connection.js')).Connection
exports.Queue = require(path.join(__dirname, 'lib', 'queue.js')).Queue
exports.Worker = require(path.join(__dirname, 'lib', 'worker.js')).Worker
exports.MultiWorker = require(path.join(__dirname, 'lib', 'multiWorker.js')).MultiWorker
exports.Scheduler = require(path.join(__dirname, 'lib', 'scheduler.js')).Scheduler
exports.PluginRunner = require(path.join(__dirname, 'lib', 'pluginRunner.js'))
exports.Plugin = require(path.join(__dirname, 'lib', 'plugin.js')).Plugin

webpack似乎根本无法解析这些语句,因此不会去抓取connection.js或queue.js或任何这些文件,因此自然而然地,我在生产环境中运行时遇到模块未找到错误。不仅仅是文件没有被捆绑,这就是我在捆绑文件exports.Connection = __webpack_require__(7)(path.join(__dirname, 'lib', 'connection.js')).Connection;中得到的结果 只有一个捆绑文件,代码将如何找到该lib文件夹!

这是我的webpack配置:

const path = require('path');
// eslint-disable-next-line import/no-unresolved
const slsw = require('serverless-webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
  mode: 'none',
  entry: slsw.lib.entries,
  target: 'node',
  node: {
    __dirname: false,
    __filename: false,
  },
  module: {
    rules: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      parser: {
        node: {
          __dirname: false,
          __filename: false,
        },
      },
      exclude: /node_modules/,
    }],
  },
  externals: ['aws-sdk', 'electron'],
  plugins: [
    // new UglifyJSPlugin({
    //   uglifyOptions: {
    //     mangle: false,
    //     output: { comments: false },
    //     compress: { warnings: false },
    //   },
    // }),
  ],
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
};

任何帮助将不胜感激!

0 个答案:

没有答案