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