]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/config/webpack.prod.js
Fix prod build
[github/Chocobozzz/PeerTube.git] / client / config / webpack.prod.js
index 447d47415ccbc331eab705253d5d078cfa2e305c..1484e2ac24a8712b718454a0f3e381164c4a8edc 100644 (file)
@@ -9,14 +9,12 @@ const commonConfig = require('./webpack.common.js') // the settings that are com
 /**
  * Webpack Plugins
  */
-// const ProvidePlugin = require('webpack/lib/ProvidePlugin')
 const DefinePlugin = require('webpack/lib/DefinePlugin')
-const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
-// const IgnorePlugin = require('webpack/lib/IgnorePlugin')
-// const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
+const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
+const OptimizeJsPlugin = require('optimize-js-plugin')
 const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
-const WebpackMd5Hash = require('webpack-md5-hash')
+const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
 
 /**
  * Webpack Constants
@@ -28,7 +26,8 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
   host: HOST,
   port: PORT,
   ENV: ENV,
-  HMR: false
+  HMR: false,
+  API_URL: ''
 })
 
 module.exports = function (env) {
@@ -69,7 +68,7 @@ module.exports = function (env) {
       *
       * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
       */
-      sourceMapFilename: '[name].[chunkhash].bundle.map',
+      sourceMapFilename: '[file].map',
 
       /**
       * The filename of non-entry chunks as relative path
@@ -77,15 +76,11 @@ module.exports = function (env) {
       *
       * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
       */
-      chunkFilename: '[id].[chunkhash].chunk.js',
+      chunkFilename: '[name].[chunkhash].chunk.js',
 
       publicPath: '/client/'
     },
 
-    externals: {
-      webtorrent: 'WebTorrent'
-    },
-
     /**
      * Add additional plugins to the compiler.
      *
@@ -94,12 +89,15 @@ module.exports = function (env) {
     plugins: [
 
       /**
-       * Plugin: WebpackMd5Hash
-       * Description: Plugin to replace a standard webpack chunkhash with md5.
+       * Webpack plugin to optimize a JavaScript file for faster initial load
+       * by wrapping eagerly-invoked functions.
        *
-       * See: https://www.npmjs.com/package/webpack-md5-hash
+       * See: https://github.com/vigneshshanmugam/optimize-js-plugin
        */
-      new WebpackMd5Hash(),
+
+      new OptimizeJsPlugin({
+        sourceMap: false
+      }),
 
       /**
        * Plugin: DedupePlugin
@@ -124,13 +122,15 @@ module.exports = function (env) {
       new DefinePlugin({
         'ENV': JSON.stringify(METADATA.ENV),
         'HMR': METADATA.HMR,
+        'API_URL': JSON.stringify(METADATA.API_URL),
+        'process.version': JSON.stringify(process.version),
         'process.env': {
           'ENV': JSON.stringify(METADATA.ENV),
           'NODE_ENV': JSON.stringify(METADATA.ENV),
           'HMR': METADATA.HMR
         }
       }),
-/**
+      /**
       * Plugin: UglifyJsPlugin
       * Description: Minimize all JavaScript output of chunks.
       * Loaders are switched into minimizing mode.
@@ -154,22 +154,39 @@ module.exports = function (env) {
         // comments: true, //debug
 
         beautify: false, // prod
+        output: {
+          comments: false
+        }, // prod
         mangle: {
-          screw_ie8: true,
-          keep_fnames: true
+          screw_ie8: true
         }, // prod
         compress: {
           screw_ie8: true,
-          warnings: false
-        }, // prod
-        comments: false // prod
+          warnings: false,
+          conditionals: true,
+          unused: true,
+          comparisons: true,
+          sequences: true,
+          dead_code: true,
+          evaluate: true,
+          if_return: true,
+          join_vars: true,
+          negate_iife: false // we need this for lazy v8
+        }
       }),
 
       new NormalModuleReplacementPlugin(
         /angular2-hmr/,
-        helpers.root('config/modules/angular2-hmr-prod.js')
+        helpers.root('config/empty.js')
       ),
 
+      new NormalModuleReplacementPlugin(
+        /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
+        helpers.root('config/empty.js')
+      ),
+
+      new HashedModuleIdsPlugin(),
+
       /**
       * Plugin: IgnorePlugin
       * Description: Don’t generate modules for requests matching the provided RegExp.
@@ -198,6 +215,7 @@ module.exports = function (env) {
       * See: https://gist.github.com/sokra/27b24881210b56bbaff7
       */
       new LoaderOptionsPlugin({
+        minimize: true,
         debug: false,
         options: {
 
@@ -251,7 +269,8 @@ module.exports = function (env) {
     node: {
       global: true,
       crypto: 'empty',
-      process: false,
+      fs: 'empty',
+      process: true,
       module: false,
       clearImmediate: false,
       setImmediate: false