node.js - 在 nodejs 的服务器端使用 webpack

标签 node.js webpack

我一直在尝试将 webpack 与 nodejs 应用程序一起使用,并且客户端运行良好 - 他们网站上有相当不错的文档 + 来自谷歌搜索的链接。

有人在 nodejs 的服务器端使用过 webpack 吗?或者请引导我到任何有用的链接。

谢谢。

最佳答案

这可能有用:http://jlongster.com/Backend-Apps-with-Webpack--Part-I

关键是在 webpack 配置文件中将所有第三方模块(在 node_modules 目录中)外部化

最终配置文件

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 = {
  entry: './src/main.js',
  target: 'node',
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'backend.js'
  },
  externals: nodeModules,
  plugins: [
    new webpack.IgnorePlugin(/\.(css|less)$/),
    new webpack.BannerPlugin('require("source-map-support").install();',
                             { raw: true, entryOnly: false })
  ],
  devtool: 'sourcemap'
}

关于node.js - 在 nodejs 的服务器端使用 webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911491/

相关文章:

typescript - ./node_modules/graphql/index.mjs 中的错误 49 :0-53:205 Can't reexport the named export

reactjs - 如何使用 Webpack 创建与容器应用程序共享库的微前端 bundle ?

node.js - 无法安装 npm 包 ||没有权限

javascript - 在这种情况下需要对 Node.js 中的函数进行阻塞调用吗?

angularjs - 如何在均值栈中进行支付网关流程?

node.js - cypress 无法清除本地存储对象

node.js - npm 未满足对正在安装的包的对等依赖性

javascript - Webpack 设置包含 flag-icon-css

webpack - babelRelayPlugin、transform-runtime、passPerPreset 是做什么的? (babel+webpack配置)

javascript - 了解 Mongoose 子文档