]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/webpack/webpack.video-embed.js
Upgrade client dependencies
[github/Chocobozzz/PeerTube.git] / client / webpack / webpack.video-embed.js
index 5a4e35deac3e1ce5e9599b7e396e9dc7cce07dc9..ef17deeb6ce04c14fd48ac153ff86e6b01dc84fe 100644 (file)
@@ -1,19 +1,17 @@
 const helpers = require('./helpers')
+const path = require('path')
 
-const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
 const HtmlWebpackPlugin = require('html-webpack-plugin')
-const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
-const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
+const TerserPlugin = require('terser-webpack-plugin')
 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
-const ExtractTextPlugin = require('extract-text-webpack-plugin')
-const PurifyCSSPlugin = require('purifycss-webpack')
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
 
 module.exports = function () {
-  const isProd = process.env.NODE_ENV === 'production'
-
   const configuration = {
     entry: {
-      'video-embed': './src/standalone/videos/embed.ts'
+      'video-embed': './src/standalone/videos/embed.ts',
+      'player': './src/standalone/player/player.ts',
+      'test-embed': './src/standalone/videos/test-embed.ts'
     },
 
     resolve: {
@@ -24,18 +22,29 @@ module.exports = function () {
        */
       extensions: [ '.ts', '.js', '.json', '.scss' ],
 
-      modules: [ helpers.root('src'), helpers.root('node_modules') ]
+      modules: [ helpers.root('src'), 'node_modules' ],
+
+      alias: {
+        'video.js$': path.resolve('node_modules/video.js/core.js'),
+        '@root-helpers': path.resolve('src/root-helpers'),
+        '@shared/models': path.resolve('../shared/models'),
+        '@shared/core-utils': path.resolve('../shared/core-utils')
+      }
     },
 
     output: {
       path: helpers.root('dist/standalone/videos'),
-      filename: '[name].[hash].bundle.js',
+
+      filename: process.env.ANALYZE_BUNDLE === 'true'
+        ? '[name].bundle.js'
+        : '[name].[hash].bundle.js',
+
       sourceMapFilename: '[file].map',
-      chunkFilename: '[id].chunk.js',
+      chunkFilename: '[id].[hash].chunk.js',
       publicPath: '/client/standalone/videos/'
     },
 
-    // devtool: 'source-map',
+    devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
 
     module: {
 
@@ -44,39 +53,39 @@ module.exports = function () {
           test: /\.ts$/,
           use: [
             {
-              loader: 'awesome-typescript-loader',
+              loader: 'ts-loader',
               options: {
-                configFileName: 'tsconfig.json'
+                configFile: 'tsconfig.base.json'
               }
             }
-          ],
-          exclude: [/\.(spec|e2e)\.ts$/]
+          ]
         },
 
         {
           test: /\.(sass|scss)$/,
-          use: ExtractTextPlugin.extract({
-            fallback: 'style-loader',
-            use: [
-              {
-                loader: 'css-loader',
-                options: {
-                  sourceMap: true,
-                  importLoaders: 1
-                }
-              },
-              'resolve-url-loader',
-              {
-                loader: 'sass-loader',
-                options: {
+          use: [
+            MiniCssExtractPlugin.loader,
+
+            {
+              loader: 'css-loader',
+              options: {
+                sourceMap: true,
+                importLoaders: 1
+              }
+            },
+
+            {
+              loader: 'sass-loader',
+              options: {
+                sassOptions: {
                   sourceMap: true,
                   includePaths: [
                     helpers.root('src/sass/include')
                   ]
                 }
               }
-            ]
-          })
+            }
+          ]
         },
 
         {
@@ -84,7 +93,8 @@ module.exports = function () {
           use: 'raw-loader',
           exclude: [
             helpers.root('src/index.html'),
-            helpers.root('src/standalone/videos/embed.html')
+            helpers.root('src/standalone/videos/embed.html'),
+            helpers.root('src/standalone/videos/test-embed.html')
           ]
         },
 
@@ -100,26 +110,36 @@ module.exports = function () {
     },
 
     plugins: [
-      new ExtractTextPlugin({
-        filename: '[name].[hash].css'
+      new MiniCssExtractPlugin({
+        filename: process.env.ANALYZE_BUNDLE === 'true'
+          ? '[name].css'
+          : '[name].[hash].css'
       }),
 
-      new PurifyCSSPlugin({
-        paths: [ helpers.root('src/standalone/videos/embed.ts') ],
-        purifyOptions: {
-          minify: true,
-          whitelist: [ '*vjs*', '*video-js*' ]
+      new HtmlWebpackPlugin({
+        template: 'src/standalone/videos/embed.html',
+        filename: 'embed.html',
+        title: 'PeerTube',
+        chunksSortMode: 'auto',
+        inject: 'body',
+        chunks: ['video-embed'],
+        minify: {
+          collapseWhitespace: true,
+          removeComments: false,
+          removeRedundantAttributes: true,
+          removeScriptTypeAttributes: true,
+          removeStyleLinkTypeAttributes: true,
+          useShortDoctype: true
         }
       }),
 
-      new CheckerPlugin(),
-
       new HtmlWebpackPlugin({
-        template: 'src/standalone/videos/embed.html',
-        filename: 'embed.html',
+        template: '!!html-loader!src/standalone/videos/test-embed.html',
+        filename: 'test-embed.html',
         title: 'PeerTube',
-        chunksSortMode: 'dependency',
-        inject: 'body'
+        chunksSortMode: 'auto',
+        inject: 'body',
+        chunks: ['test-embed']
       }),
 
       /**
@@ -137,6 +157,27 @@ module.exports = function () {
       })
     ],
 
+    optimization: {
+      minimizer: [
+        new TerserPlugin({
+          terserOptions: {
+            ecma: 6,
+            warnings: false,
+            ie8: false,
+            mangle: true,
+            compress: {
+              passes: 3,
+              pure_getters: true
+            },
+            output: {
+              ascii_only: true,
+              comments: false
+            }
+          }
+        })
+      ]
+    },
+
     performance: {
       maxEntrypointSize: 700000, // 600kB
       maxAssetSize: 700000
@@ -153,28 +194,5 @@ module.exports = function () {
     }
   }
 
-  if (isProd) {
-    configuration.plugins.push(
-      new UglifyJsPlugin({
-        uglifyOptions: {
-          ecma: 6,
-          warnings: false,
-          ie8: false,
-          mangle: true,
-          compress: {
-            passes: 3,
-            pure_getters: true
-          },
-          output: {
-            ascii_only: true,
-            comments: false
-          }
-        }
-      }),
-
-      new HashedModuleIdsPlugin()
-    )
-  }
-
   return configuration
 }