2
1

webpack.video-embed.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. const helpers = require('./helpers')
  2. const path = require('path')
  3. const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
  4. const HtmlWebpackPlugin = require('html-webpack-plugin')
  5. const TerserPlugin = require('terser-webpack-plugin')
  6. const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
  7. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  8. const PurifyCSSPlugin = require('purifycss-webpack')
  9. module.exports = function () {
  10. const configuration = {
  11. entry: {
  12. 'video-embed': './src/standalone/videos/embed.ts',
  13. 'player': './src/standalone/player/player.ts',
  14. 'test-embed': './src/standalone/videos/test-embed.ts'
  15. },
  16. resolve: {
  17. /*
  18. * An array of extensions that should be used to resolve modules.
  19. *
  20. * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
  21. */
  22. extensions: [ '.ts', '.js', '.json', '.scss' ],
  23. modules: [ helpers.root('src'), helpers.root('node_modules') ],
  24. alias: {
  25. 'video.js$': path.resolve('node_modules/video.js/dist/alt/video.core.js')
  26. }
  27. },
  28. output: {
  29. path: helpers.root('dist/standalone/videos'),
  30. filename: '[name].[hash].bundle.js',
  31. sourceMapFilename: '[file].map',
  32. chunkFilename: '[id].chunk.js',
  33. publicPath: '/client/standalone/videos/'
  34. },
  35. devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
  36. module: {
  37. rules: [
  38. {
  39. test: /\.ts$/,
  40. use: [
  41. {
  42. loader: 'awesome-typescript-loader',
  43. options: {
  44. configFileName: 'tsconfig.json'
  45. }
  46. }
  47. ],
  48. exclude: [/\.(spec|e2e)\.ts$/]
  49. },
  50. {
  51. test: /\.(sass|scss)$/,
  52. use: ExtractTextPlugin.extract({
  53. fallback: 'style-loader',
  54. use: [
  55. {
  56. loader: 'css-loader',
  57. options: {
  58. sourceMap: true,
  59. importLoaders: 1
  60. }
  61. },
  62. // {
  63. // loader: 'resolve-url-loader',
  64. // options: {
  65. // debug: true
  66. // }
  67. // },
  68. {
  69. loader: 'sass-loader',
  70. options: {
  71. sourceMap: true,
  72. includePaths: [
  73. helpers.root('src/sass/include')
  74. ]
  75. }
  76. }
  77. ]
  78. })
  79. },
  80. {
  81. test: /\.html$/,
  82. use: 'raw-loader',
  83. exclude: [
  84. helpers.root('src/index.html'),
  85. helpers.root('src/standalone/videos/embed.html'),
  86. helpers.root('src/standalone/videos/test-embed.html')
  87. ]
  88. },
  89. {
  90. test: /\.(jpg|png|gif)$/,
  91. use: 'url-loader'
  92. },
  93. { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
  94. { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
  95. ]
  96. },
  97. plugins: [
  98. new ExtractTextPlugin({
  99. filename: '[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 CheckerPlugin(),
  112. new HtmlWebpackPlugin({
  113. template: 'src/standalone/videos/embed.html',
  114. filename: 'embed.html',
  115. title: 'PeerTube',
  116. chunksSortMode: 'dependency',
  117. inject: 'body',
  118. chunks: ['video-embed']
  119. }),
  120. new HtmlWebpackPlugin({
  121. template: '!!html-loader!src/standalone/videos/test-embed.html',
  122. filename: 'test-embed.html',
  123. title: 'PeerTube',
  124. chunksSortMode: 'dependency',
  125. inject: 'body',
  126. chunks: ['test-embed']
  127. }),
  128. /**
  129. * Plugin LoaderOptionsPlugin (experimental)
  130. *
  131. * See: https://gist.github.com/sokra/27b24881210b56bbaff7
  132. */
  133. new LoaderOptionsPlugin({
  134. options: {
  135. context: __dirname,
  136. output: {
  137. path: helpers.root('dist')
  138. }
  139. }
  140. })
  141. ],
  142. optimization: {
  143. minimizer: [
  144. new TerserPlugin({
  145. terserOptions: {
  146. ecma: 6,
  147. warnings: false,
  148. ie8: false,
  149. mangle: true,
  150. compress: {
  151. passes: 3,
  152. pure_getters: true
  153. },
  154. output: {
  155. ascii_only: true,
  156. comments: false
  157. }
  158. }
  159. })
  160. ]
  161. },
  162. performance: {
  163. maxEntrypointSize: 700000, // 600kB
  164. maxAssetSize: 700000
  165. },
  166. node: {
  167. global: true,
  168. crypto: 'empty',
  169. fs: 'empty',
  170. process: true,
  171. module: false,
  172. clearImmediate: false,
  173. setImmediate: false
  174. }
  175. }
  176. return configuration
  177. }