在 nodejs 的服务器端使用 webpack [英] using webpack on server side of nodejs

查看:69
本文介绍了在 nodejs 的服务器端使用 webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to use webpack with a nodejs application, and the client side is going fine - a reasonably good documentation on their website + links from google search.

有没有人在 nodejs 的服务器端使用过 webpack?或者请指导我找到任何有用的链接.

Has anyone used webpack on server side of nodejs? or please guide me to any useful links.

谢谢.

推荐答案

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

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

Key point is to make external all third party module (in node_modules directory) in webpack config file

最终配置文件

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'
}

这篇关于在 nodejs 的服务器端使用 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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