webpack.video-embed.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 ExtractTextPlugin = require('extract-text-webpack-plugin')
  7. const PurifyCSSPlugin = require('purifycss-webpack')
  8. module.exports = function () {
  9. const configuration = {
  10. entry: {
  11. 'video-embed': './src/standalone/videos/embed.ts',
  12. 'player': './src/standalone/player/player.ts',
  13. 'test-embed': './src/standalone/videos/test-embed.ts'
  14. },
  15. resolve: {
  16. /*
  17. * An array of extensions that should be used to resolve modules.
  18. *
  19. * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
  20. */
  21. extensions: [ '.ts', '.js', '.json', '.scss' ],
  22. modules: [ helpers.root('src'), helpers.root('node_modules') ],
  23. alias: {
  24. 'video.js$': path.resolve('node_modules/video.js/core.js'),
  25. '@root-helpers': path.resolve('src/root-helpers'),
  26. '@shared/models': path.resolve('../shared/models'),
  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: ExtractTextPlugin.extract({
  55. fallback: 'style-loader',
  56. use: [
  57. {
  58. loader: 'css-loader',
  59. options: {
  60. sourceMap: true,
  61. importLoaders: 1
  62. }
  63. },
  64. {
  65. loader: 'sass-loader',
  66. options: {
  67. sassOptions: {
  68. sourceMap: true,
  69. includePaths: [
  70. helpers.root('src/sass/include')
  71. ]
  72. }
  73. }
  74. }
  75. ]
  76. })
  77. },
  78. {
  79. test: /\.html$/,
  80. use: 'raw-loader',
  81. exclude: [
  82. helpers.root('src/index.html'),
  83. helpers.root('src/standalone/videos/embed.html'),
  84. helpers.root('src/standalone/videos/test-embed.html')
  85. ]
  86. },
  87. {
  88. test: /\.(jpg|png|gif)$/,
  89. use: 'url-loader'
  90. },
  91. { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
  92. { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
  93. ]
  94. },
  95. plugins: [
  96. new ExtractTextPlugin({
  97. filename: process.env.ANALYZE_BUNDLE === 'true'
  98. ? '[name].css'
  99. : '[name].[hash].css'
  100. }),
  101. new PurifyCSSPlugin({
  102. paths: [
  103. helpers.root('src/standalone/videos/embed.ts'),
  104. helpers.root('src/standalone/videos/test-embed.html')
  105. ],
  106. purifyOptions: {
  107. minify: true,
  108. whitelist: [ '*vjs*', '*video-js*' ]
  109. }
  110. }),
  111. new HtmlWebpackPlugin({
  112. template: 'src/standalone/videos/embed.html',
  113. filename: 'embed.html',
  114. title: 'PeerTube',
  115. chunksSortMode: 'auto',
  116. inject: 'body',
  117. chunks: ['video-embed']
  118. }),
  119. new HtmlWebpackPlugin({
  120. template: '!!html-loader!src/standalone/videos/test-embed.html',
  121. filename: 'test-embed.html',
  122. title: 'PeerTube',
  123. chunksSortMode: 'auto',
  124. inject: 'body',
  125. chunks: ['test-embed']
  126. }),
  127. /**
  128. * Plugin LoaderOptionsPlugin (experimental)
  129. *
  130. * See: https://gist.github.com/sokra/27b24881210b56bbaff7
  131. */
  132. new LoaderOptionsPlugin({
  133. options: {
  134. context: __dirname,
  135. output: {
  136. path: helpers.root('dist')
  137. }
  138. }
  139. })
  140. ],
  141. optimization: {
  142. minimizer: [
  143. new TerserPlugin({
  144. terserOptions: {
  145. ecma: 6,
  146. warnings: false,
  147. ie8: false,
  148. mangle: true,
  149. compress: {
  150. passes: 3,
  151. pure_getters: true
  152. },
  153. output: {
  154. ascii_only: true,
  155. comments: false
  156. }
  157. }
  158. })
  159. ]
  160. },
  161. performance: {
  162. maxEntrypointSize: 700000, // 600kB
  163. maxAssetSize: 700000
  164. },
  165. node: {
  166. global: true,
  167. crypto: 'empty',
  168. fs: 'empty',
  169. process: true,
  170. module: false,
  171. clearImmediate: false,
  172. setImmediate: false
  173. }
  174. }
  175. return configuration
  176. }