Webpacker不会在生产中缩小JS

问题描述

我正在开发一个使用Webpacker的React应用。我们的生产代码尚未精简,我的任务是确定原因。我在文档中找不到有关如何最小化生产代码的任何内容。似乎默认情况下它应该处于启用状态,所以我猜测我们将在某处禁用它,但是我不确定在哪里。

这是我们的Webpacker yaml配置:

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  check_yarn_integrity: false
  webpack_compile_output: false

  # Additional paths webpack should lookup modules
  # ['app/assets','engine/foo/app/assets']
  resolved_paths: ['app/assets']

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: true

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .jsx
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: false

  # Verifies that versions and hashed value of the package contents in the project's package.json
  check_yarn_integrity: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    http: true
    host: webpacker
    port: 3035
    public: https://webpacker.local.website.com:443
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'
      poll: 1000
      aggregate_timeout: 100


test:
  <<: *default

deployed: &deployed
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

production:
  <<: *deployed

staging:
  <<: *deployed

...以及我们的生产Webpack文件:

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();

const environment = require('./environment');

var ManifestPlugin = require('webpack-manifest-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const config = environment.toWebpackConfig();
config.plugins.prepend = (new ManifestPlugin());

config.optimization = {
  minimizer: [new UglifyJsPlugin({
    parallel: 4,})],}

module.exports = smp.wrap(config);

我应该寻找什么来使我们的生产版本的最小化工作?这里有什么是罪魁祸首吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)