Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Webpack-捆绑除angular universal中的一个外的所有节点模块_Node.js_Angular_Webpack_Angular Universal - Fatal编程技术网

Node.js Webpack-捆绑除angular universal中的一个外的所有节点模块

Node.js Webpack-捆绑除angular universal中的一个外的所有节点模块,node.js,angular,webpack,angular-universal,Node.js,Angular,Webpack,Angular Universal,我用angular制作了一个网络应用程序。我想要使用Angular Universal进行服务器端渲染。 构建此类服务器的最佳方法是使用webpack,这是适用于大多数情况的标准配置: const path = require('path'); const webpack = require('webpack'); module.exports = { entry: { server: './server.ts' }, resolve: { extensions: ['.js', '.

我用angular制作了一个网络应用程序。我想要使用Angular Universal进行服务器端渲染。 构建此类服务器的最佳方法是使用webpack,这是适用于大多数情况的标准配置:

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

module.exports = {
  entry: { server: './server.ts' },
  resolve: { extensions: ['.js', '.ts'] },
  target: 'node',
  externals: [/node_modules/],
  mode: 'none',
  // this makes sure we include node_modules and other 3rd party libraries
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [{ test: /\.ts$/, loader: 'ts-loader', exclude: /server-local/ }]
  },
  plugins: [
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for 'WARNING Critical dependency: the request of a dependency is an expression'
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
};
但我遇到了一个问题:我在服务器中使用节点模块pugmailer,它使用uglifyjs作为依赖项,而不是dev依赖项。Webpack不支持捆绑uglify js,因此我发现解决此问题的唯一方法是:

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

module.exports = {
  externals: [nodeExternals()],
  ... //the rest is unchanged
};
但这是不可接受的:这样一来,所有的node_模块都不会捆绑在一起,我必须将整个node_模块dir保存在我的生产服务器中

除了uglify js,是否有办法将所有节点_模块捆绑到一个文件中

我想要的结果是:

dist
----server.js //built with webpack, contains all node_modules except uglify-js
----other dists folder
node_modules
----uglify-js //Only this dependency in node_modules