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