webpack.video-embed.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const helpers = require('./helpers')
  2. const path = require('path')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const TerserPlugin = require('terser-webpack-plugin')
  5. const ProvidePlugin = require('webpack/lib/ProvidePlugin')
  6. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  7. module.exports = function () {
  8. const configuration = {
  9. entry: {
  10. 'video-embed': './src/standalone/videos/embed.ts',
  11. 'player': './src/standalone/embed-player-api/player.ts',
  12. 'test-embed': './src/standalone/videos/test-embed.ts'
  13. },
  14. resolve: {
  15. /*
  16. * An array of extensions that should be used to resolve modules.
  17. *
  18. * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
  19. */
  20. extensions: [ '.ts', '.js', '.json', '.scss' ],
  21. modules: [ helpers.root('src'), 'node_modules' ],
  22. symlinks: true,
  23. alias: {
  24. 'video.js$': path.resolve('node_modules/video.js/core.js'),
  25. 'hls.js$': path.resolve('node_modules/hls.js/dist/hls.light.js'),
  26. '@root-helpers': path.resolve('src/root-helpers')
  27. },
  28. fallback: {
  29. fs: [ path.resolve('src/shims/noop.ts') ],
  30. path: [ path.resolve('src/shims/path.ts') ],
  31. crypto: [ path.resolve('src/shims/noop.ts') ]
  32. }
  33. },
  34. output: {
  35. path: helpers.root('dist/standalone/videos'),
  36. filename: process.env.ANALYZE_BUNDLE === 'true'
  37. ? '[name].bundle.js'
  38. : '[name].[contenthash].bundle.js',
  39. sourceMapFilename: '[file].map',
  40. chunkFilename: process.env.ANALYZE_BUNDLE === 'true'
  41. ? '[name].chunk.js'
  42. : '[id].[contenthash].chunk.js',
  43. publicPath: '/client/standalone/videos/'
  44. },
  45. devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
  46. module: {
  47. rules: [
  48. {
  49. test: /\.ts$/,
  50. use: [
  51. getBabelLoader(),
  52. {
  53. loader: 'ts-loader',
  54. options: {
  55. configFile: helpers.root('src/standalone/videos/tsconfig.json')
  56. }
  57. }
  58. ]
  59. },
  60. {
  61. test: /\.m?js$/,
  62. use: [ getBabelLoader() ]
  63. },
  64. {
  65. test: /\.(sass|scss)$/,
  66. use: [
  67. MiniCssExtractPlugin.loader,
  68. {
  69. loader: 'css-loader',
  70. options: {
  71. sourceMap: true,
  72. importLoaders: 1
  73. }
  74. },
  75. {
  76. loader: 'sass-loader',
  77. options: {
  78. sassOptions: {
  79. sourceMap: true,
  80. includePaths: [
  81. helpers.root('src/sass/include')
  82. ]
  83. }
  84. }
  85. }
  86. ]
  87. },
  88. {
  89. test: /\.html$/,
  90. exclude: [
  91. helpers.root('src/index.html'),
  92. helpers.root('src/standalone/videos/embed.html'),
  93. helpers.root('src/standalone/videos/test-embed.html')
  94. ],
  95. type: 'asset/source'
  96. },
  97. {
  98. test: /\.(jpg|png|gif|svg)$/,
  99. type: 'asset'
  100. },
  101. {
  102. test: /\.(ttf|eot|woff2?)$/,
  103. type: 'asset'
  104. }
  105. ]
  106. },
  107. plugins: [
  108. new ProvidePlugin({
  109. process: 'process/browser',
  110. Buffer: [ 'buffer', 'Buffer' ]
  111. }),
  112. new MiniCssExtractPlugin({
  113. filename: process.env.ANALYZE_BUNDLE === 'true'
  114. ? '[name].css'
  115. : '[name].[contenthash].css'
  116. }),
  117. new HtmlWebpackPlugin({
  118. template: 'src/standalone/videos/embed.html',
  119. filename: 'embed.html',
  120. title: 'PeerTube',
  121. chunksSortMode: 'auto',
  122. inject: 'body',
  123. chunks: [ 'video-embed' ],
  124. minify: {
  125. collapseWhitespace: true,
  126. removeComments: false,
  127. removeRedundantAttributes: true,
  128. removeScriptTypeAttributes: true,
  129. removeStyleLinkTypeAttributes: true,
  130. useShortDoctype: true
  131. }
  132. }),
  133. new HtmlWebpackPlugin({
  134. template: '!!html-loader!src/standalone/videos/test-embed.html',
  135. filename: 'test-embed.html',
  136. title: 'PeerTube',
  137. chunksSortMode: 'auto',
  138. inject: 'body',
  139. chunks: [ 'test-embed' ]
  140. })
  141. ],
  142. optimization: {
  143. minimizer: [
  144. new TerserPlugin({
  145. terserOptions: {
  146. ecma: 6,
  147. warnings: false,
  148. ie8: false,
  149. safari10: false,
  150. mangle: true,
  151. compress: {
  152. passes: 3,
  153. pure_getters: true
  154. },
  155. output: {
  156. ascii_only: true,
  157. comments: false
  158. }
  159. }
  160. })
  161. ]
  162. },
  163. performance: {
  164. maxEntrypointSize: 700000, // 600kB
  165. maxAssetSize: 700000
  166. },
  167. node: {
  168. global: true
  169. }
  170. }
  171. return configuration
  172. }
  173. function getBabelLoader () {
  174. return {
  175. loader: 'babel-loader',
  176. options: {
  177. presets: [
  178. [
  179. '@babel/preset-env', {
  180. targets: 'last 1 Chrome version, last 2 Edge major versions, Firefox ESR, Safari >= 12, ios_saf >= 12'
  181. }
  182. ]
  183. ]
  184. }
  185. }
  186. }