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