澳门银河网上官方赌场_老品牌值得信赖

ITKeyword,专注技术干货聚合推荐

注册 | 登录

node.js - Using webpack with NodeJs native modules

itPublisher 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
地址https://www.aliyun.com/minisite/goods

推荐:node.js之打包工具webpack

什么是 Webpack Webpack 是一个模块打包器。它将根据模块的依赖关系进行静态分析,然后将这些模块按照指定的规则生成对应的静态资源。 为什么重复造轮子   市

I have an Node.js app that has few native module which are created via node-gyp. These modules do not end up in "node_modules" and are being required via standard "require" from Node...

My webpack config is based on this article If I run the app "unpackaged" - everything works fine... But after I run "webpack -p --progress" and try to run it, I get following:

X:\myapp>node main-backend.bundle.js env=production port=80 ssl_port=443
[Error: Cannot open X:\myapp\lib\modules\my-module\build\Release\mymodule.node: Error: The specified module could not be found.

I made sure all the loaders are npm installed. From the error, I can tell that the path is correct (relative to server.native.js) but obviously not to app.js...However, this "just works" when using regular node.js and I am not sure if this is even the crux of the issue...

I would appreciate any help!

Here is abridged layout of my app

myapp/
    app.js
    node_modules/
    lib/
      modules/
        my-module/
           src/
             one.cc
             one.h
           lib/
             server.native.js
           bindings.gyp
           build/
             Release/
               mymodule.node

server.native.js is very simple, calling native module

try {
    module.exports = require('../build/Release/mymodule.node');
    console.log('native module loaded...');
} catch (err) {
    console.log(err);
}

And here is my webpack.config.js

var webpack = require("webpack");
var path = require("path");
var fs = require("fs");

var nodeModules = {};
fs.readdirSync("node_modules")
  .filter(function(x) {
    return [".bin"].indexOf(x) === -1;
  })
  .forEach(function(mod) {
    nodeModules[mod] = "commonjs " + mod;
  });


module.exports = [
  {
    name: "server-side",
    context: __dirname,
    entry: {
      "main-backend": "./app.js"
    },
    target: "node",
    output: {
      path: __dirname,
      filename: "[name].bundle.js",
      chunkFilename: "[id].bundle.js"
    },
    module: {
      loaders: [
        { test: /\.json$/,   loader: "json-loader" },
        { test: /\.jade$/,   loader: "jade-loader" },
        { test: /\.node$/,   loader: "node-loader" }
      ]
    },
    externals: [nodeModules],
    resolve: {
      extensions: [ "", ".js", ".node"]
    },
    plugins: [
      new webpack.IgnorePlugin(/\.(css|less)$/)
      new webpack.BannerPlugin("require(\"source-map-support\").install();", { raw: true, entryOnly: false })
    ],
    node: {
      __dirname: true,
      __filename: true
    },
    devtool: "sourcemap",
    profile: true
  }
];
node.js module server-side webpack
|
  this question
edited Sep 29 '15 at 15:34 asked Sep 28 '15 at 21:33 zam6ak 3,198 6 33 72      You have externals: [nodeModules], instead of externals: nodeModules, as per the article –  zlog Nov 26 '15 at 14:35

 | 

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。

澳门银河网上官方赌场 <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <蜘蛛词>| <文本链> <文本链> <文本链> <文本链> <文本链> <文本链>