]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/webpack/webpack.video-embed.js
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / client / webpack / webpack.video-embed.js
index f6d532556c70b6a86b6fc557576ca65b203343f6..e25677872e4f0842b7f43e845f964f18aae04a7a 100644 (file)
@@ -1,12 +1,10 @@
 const helpers = require('./helpers')
 const path = require('path')
 
-const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
 const HtmlWebpackPlugin = require('html-webpack-plugin')
 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 ProvidePlugin = require('webpack/lib/ProvidePlugin')
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
 
 module.exports = function () {
   const configuration = {
@@ -24,18 +22,41 @@ module.exports = function () {
        */
       extensions: [ '.ts', '.js', '.json', '.scss' ],
 
-      modules: [ helpers.root('src'), helpers.root('node_modules') ],
+      modules: [ helpers.root('src'), 'node_modules' ],
+
+      symlinks: true,
 
       alias: {
-        'video.js$': path.resolve('node_modules/video.js/dist/alt/video.core.novtt.js')
+        'video.js$': path.resolve('node_modules/video.js/core.js'),
+        'hls.js$': path.resolve('node_modules/hls.js/dist/hls.light.js'),
+        '@root-helpers': path.resolve('src/root-helpers'),
+        '@shared/models': path.resolve('../shared/models'),
+        '@shared/core-utils': path.resolve('../shared/core-utils')
+      },
+
+      fallback: {
+        fs: [ path.resolve('src/shims/noop.ts') ],
+        http: [ path.resolve('src/shims/http.ts') ],
+        https: [ path.resolve('src/shims/https.ts') ],
+        path: [ path.resolve('src/shims/path.ts') ],
+        stream: [ path.resolve('src/shims/stream.ts') ],
+        crypto: [ path.resolve('src/shims/noop.ts') ]
       }
     },
 
     output: {
       path: helpers.root('dist/standalone/videos'),
-      filename: '[name].[hash].bundle.js',
+
+      filename: process.env.ANALYZE_BUNDLE === 'true'
+        ? '[name].bundle.js'
+        : '[name].[contenthash].bundle.js',
+
       sourceMapFilename: '[file].map',
-      chunkFilename: '[id].chunk.js',
+
+      chunkFilename: process.env.ANALYZE_BUNDLE === 'true'
+        ? '[name].chunk.js'
+        : '[id].[contenthash].chunk.js',
+
       publicPath: '/client/standalone/videos/'
     },
 
@@ -47,116 +68,107 @@ module.exports = function () {
         {
           test: /\.ts$/,
           use: [
+            getBabelLoader(),
+
             {
-              loader: 'awesome-typescript-loader',
+              loader: 'ts-loader',
               options: {
-                configFileName: 'tsconfig.json'
+                configFile: helpers.root('src/standalone/videos/tsconfig.json')
               }
             }
-          ],
-          exclude: [/\.(spec|e2e)\.ts$/]
+          ]
+        },
+        {
+          test: /\.m?js$/,
+          use: [ getBabelLoader() ]
         },
 
         {
           test: /\.(sass|scss)$/,
-          use: ExtractTextPlugin.extract({
-            fallback: 'style-loader',
-            use: [
-              {
-                loader: 'css-loader',
-                options: {
-                  sourceMap: true,
-                  importLoaders: 1
-                }
-              },
-              // {
-              //   loader: 'resolve-url-loader',
-              //   options: {
-              //     debug: true
-              //   }
-              // },
-              {
-                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')
                   ]
                 }
               }
-            ]
-          })
+            }
+          ]
         },
 
         {
           test: /\.html$/,
-          use: 'raw-loader',
           exclude: [
             helpers.root('src/index.html'),
             helpers.root('src/standalone/videos/embed.html'),
             helpers.root('src/standalone/videos/test-embed.html')
-          ]
+          ],
+          type: 'asset/source'
         },
 
         {
-          test: /\.(jpg|png|gif)$/,
-          use: 'url-loader'
+          test: /\.(jpg|png|gif|svg)$/,
+          type: 'asset'
         },
 
-        { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
-        { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
+        {
+          test: /\.(ttf|eot|woff2?)$/,
+          type: 'asset'
+        }
       ]
 
     },
 
     plugins: [
-      new ExtractTextPlugin({
-        filename: '[name].[hash].css'
+      new ProvidePlugin({
+        process: 'process/browser',
+        Buffer: [ 'buffer', 'Buffer' ]
       }),
 
-      new PurifyCSSPlugin({
-        paths: [
-          helpers.root('src/standalone/videos/embed.ts'),
-          helpers.root('src/standalone/videos/test-embed.html')
-        ],
-        purifyOptions: {
-          minify: true,
-          whitelist: [ '*vjs*', '*video-js*' ]
-        }
+      new MiniCssExtractPlugin({
+        filename: process.env.ANALYZE_BUNDLE === 'true'
+          ? '[name].css'
+          : '[name].[contenthash].css'
       }),
 
-      new CheckerPlugin(),
-
       new HtmlWebpackPlugin({
         template: 'src/standalone/videos/embed.html',
         filename: 'embed.html',
         title: 'PeerTube',
-        chunksSortMode: 'dependency',
+        chunksSortMode: 'auto',
         inject: 'body',
-        chunks: ['video-embed']
+        chunks: [ 'video-embed' ],
+        minify: {
+          collapseWhitespace: true,
+          removeComments: false,
+          removeRedundantAttributes: true,
+          removeScriptTypeAttributes: true,
+          removeStyleLinkTypeAttributes: true,
+          useShortDoctype: true
+        }
       }),
 
       new HtmlWebpackPlugin({
         template: '!!html-loader!src/standalone/videos/test-embed.html',
         filename: 'test-embed.html',
         title: 'PeerTube',
-        chunksSortMode: 'dependency',
+        chunksSortMode: 'auto',
         inject: 'body',
-        chunks: ['test-embed']
-      }),
-
-      /**
-       * Plugin LoaderOptionsPlugin (experimental)
-       *
-       * See: https://gist.github.com/sokra/27b24881210b56bbaff7
-       */
-      new LoaderOptionsPlugin({
-        options: {
-          context: __dirname,
-          output: {
-            path: helpers.root('dist')
-          }
-        }
+        chunks: [ 'test-embed' ]
       })
     ],
 
@@ -167,6 +179,7 @@ module.exports = function () {
             ecma: 6,
             warnings: false,
             ie8: false,
+            safari10: false,
             mangle: true,
             compress: {
               passes: 3,
@@ -187,15 +200,24 @@ module.exports = function () {
     },
 
     node: {
-      global: true,
-      crypto: 'empty',
-      fs: 'empty',
-      process: true,
-      module: false,
-      clearImmediate: false,
-      setImmediate: false
+      global: true
     }
   }
 
   return configuration
 }
+
+function getBabelLoader () {
+  return {
+    loader: 'babel-loader',
+    options: {
+      presets: [
+        [
+          '@babel/preset-env', {
+            targets: 'last 1 Chrome version, last 2 Edge major versions, Firefox ESR, Safari >= 12, ios_saf >= 12'
+          }
+        ]
+      ]
+    }
+  }
+}