Как минимизировать сервер. js файл в angular универсальной сборке - PullRequest
0 голосов
/ 09 апреля 2020

После создания моего angular ssr-приложения:

npm run build:ssr

и проверьте мою папку dist, размер сервера. js файл слишком большой> 12 МБ . есть ли способ, по крайней мере, минимизировать / унизить этот файл.

вот мой webpack.server.config. js content:

// Work around for https://github.com/angular/angular-cli/issues/7200
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");

module.exports = {
  mode: "none",
  entry: {
    // This is our Express server for Dynamic universal
    server: "./server/main.ts"
  },
  externals: [nodeExternals()],

  target: "node",
  resolve: { extensions: [".ts", ".js"] },
  optimization: {
    minimize: false
  },
  output: {
    // Puts the output at the root of the dist folder
    path: path.join(__dirname, "dist"),
    filename: "[name].js"
  },
  module: {
    noParse: /polyfills-.*\.js/,
    rules: [
      { test: /\.ts$/, loader: "ts-loader" },
      {
        // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
        // Removing this will cause deprecation warnings to appear.
        test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
        parser: { system: true }
      }
    ]
  },
  plugins: [
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, "src"), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      // fixes WARNING Critical dependency: the request of a dependency is an expression
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, "src"),
      {}
    )
  ]
};

i ' Мы пробовали решения типа express -minify- html, ничего не изменилось. я использую: Angular 8

...