從零搭建react框架(三)

1.生產環境壓縮混淆代碼

yarn add uglifyjs-webpack-plugin

webpack.prod.conf.js

  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        cache: false,
        sourceMap: false,
      })
    ]
  },

2.生產環境發佈

使用nginx作爲Web服務器,nginx配置:

    server {
        listen       7766;
        root F:\website\dist;
        index index.html;
        location / {
        	try_files $uri $uri/ @fallback;
        	index index.html;
        }
        location @fallback {
        	rewrite ^.*$ /index.html break;
    	}
    }

具體可以參考這位大哥的寫法

https://segmentfault.com/a/1190000012675012

項目github地址:https://github.com/kakaoG/react-webpack

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章