webpack.video-embed.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
  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/player/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'), helpers.root('node_modules') ],
  22. alias: {
  23. 'video.js$': path.resolve('node_modules/video.js/core.js'),
  24. '@root-helpers': path.resolve('src/root-helpers'),
  25. '@shared/models': path.resolve('../shared/models'),
  26. '@shared/core-utils': path.resolve('../shared/core-utils')
  27. }
  28. },
  29. output: {
  30. path: helpers.root('dist/standalone/videos'),
  31. filename: process.env.ANALYZE_BUNDLE === 'true'
  32. ? '[name].bundle.js'
  33. : '[name].[hash].bundle.js',
  34. sourceMapFilename: '[file].map',
  35. chunkFilename: '[id].[hash].chunk.js',
  36. publicPath: '/client/standalone/videos/'
  37. },
  38. devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
  39. module: {
  40. rules: [
  41. {
  42. test: /\.ts$/,
  43. use: [
  44. {
  45. loader: 'ts-loader',
  46. options: {
  47. configFile: 'tsconfig.base.json'
  48. }
  49. }
  50. ]
  51. },
  52. {
  53. test: /\.(sass|scss)$/,
  54. use: [
  55. MiniCssExtractPlugin.loader,
  56. {
  57. loader: 'css-loader',
  58. options: {
  59. sourceMap: true,
  60. importLoaders: 1
  61. }
  62. },
  63. {
  64. loader: 'sass-loader',
  65. options: {
  66. sassOptions: {
  67. sourceMap: true,
  68. includePaths: [
  69. helpers.root('src/sass/include')
  70. ]
  71. }
  72. }
  73. }
  74. ]
  75. },
  76. {
  77. test: /\.html$/,
  78. use: 'raw-loader',
  79. exclude: [
  80. helpers.root('src/index.html'),
  81. helpers.root('src/standalone/videos/embed.html'),
  82. helpers.root('src/standalone/videos/test-embed.html')
  83. ]
  84. },
  85. {
  86. test: /\.(jpg|png|gif)$/,
  87. use: 'url-loader'
  88. },
  89. { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
  90. { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
  91. ]
  92. },
  93. plugins: [
  94. new MiniCssExtractPlugin({
  95. filename: process.env.ANALYZE_BUNDLE === 'true'
  96. ? '[name].css'
  97. : '[name].[hash].css'
  98. }),
  99. new HtmlWebpackPlugin({
  100. template: 'src/standalone/videos/embed.html',
  101. filename: 'embed.html',
  102. title: 'PeerTube',
  103. chunksSortMode: 'auto',
  104. inject: 'body',
  105. chunks: ['video-embed'],
  106. minify: {
  107. collapseWhitespace: true,
  108. removeComments: false,
  109. removeRedundantAttributes: true,
  110. removeScriptTypeAttributes: true,
  111. removeStyleLinkTypeAttributes: true,
  112. useShortDoctype: true
  113. }
  114. }),
  115. new HtmlWebpackPlugin({
  116. template: '!!html-loader!src/standalone/videos/test-embed.html',
  117. filename: 'test-embed.html',
  118. title: 'PeerTube',
  119. chunksSortMode: 'auto',
  120. inject: 'body',
  121. chunks: ['test-embed']
  122. }),
  123. /**
  124. * Plugin LoaderOptionsPlugin (experimental)
  125. *
  126. * See: https://gist.github.com/sokra/27b24881210b56bbaff7
  127. */
  128. new LoaderOptionsPlugin({
  129. options: {
  130. context: __dirname,
  131. output: {
  132. path: helpers.root('dist')
  133. }
  134. }
  135. })
  136. ],
  137. optimization: {
  138. minimizer: [
  139. new TerserPlugin({
  140. terserOptions: {
  141. ecma: 6,
  142. warnings: false,
  143. ie8: false,
  144. mangle: true,
  145. compress: {
  146. passes: 3,
  147. pure_getters: true
  148. },
  149. output: {
  150. ascii_only: true,
  151. comments: false
  152. }
  153. }
  154. })
  155. ]
  156. },
  157. performance: {
  158. maxEntrypointSize: 700000, // 600kB
  159. maxAssetSize: 700000
  160. },
  161. node: {
  162. global: true,
  163. crypto: 'empty',
  164. fs: 'empty',
  165. process: true,
  166. module: false,
  167. clearImmediate: false,
  168. setImmediate: false
  169. }
  170. }
  171. return configuration
  172. }