]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/webpack/webpack.video-embed.js
Fetch things in bulk for the homepage
[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 '@root-helpers': path.resolve('src/root-helpers'),
31 '@shared/models': path.resolve('../shared/models'),
32 '@shared/core-utils': path.resolve('../shared/core-utils')
33 },
34
35 fallback: {
36 fs: [ path.resolve('src/shims/noop.ts') ],
37 http: [ path.resolve('src/shims/http.ts') ],
38 https: [ path.resolve('src/shims/https.ts') ],
39 path: [ path.resolve('src/shims/path.ts') ],
40 stream: [ path.resolve('src/shims/noop.ts') ],
41 crypto: [ path.resolve('src/shims/noop.ts') ]
42 }
43 },
44
45 output: {
46 path: helpers.root('dist/standalone/videos'),
47
48 filename: process.env.ANALYZE_BUNDLE === 'true'
49 ? '[name].bundle.js'
50 : '[name].[contenthash].bundle.js',
51
52 sourceMapFilename: '[file].map',
53
54 chunkFilename: process.env.ANALYZE_BUNDLE === 'true'
55 ? '[name].chunk.js'
56 : '[id].[contenthash].chunk.js',
57
58 publicPath: '/client/standalone/videos/'
59 },
60
61 devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
62
63 module: {
64
65 rules: [
66 {
67 test: /\.ts$/,
68 use: [
69 {
70 loader: 'ts-loader',
71 options: {
72 configFile: 'tsconfig.base.json'
73 }
74 }
75 ]
76 },
77
78 {
79 test: /\.(sass|scss)$/,
80 use: [
81 MiniCssExtractPlugin.loader,
82
83 {
84 loader: 'css-loader',
85 options: {
86 sourceMap: true,
87 importLoaders: 1
88 }
89 },
90
91 {
92 loader: 'sass-loader',
93 options: {
94 sassOptions: {
95 sourceMap: true,
96 includePaths: [
97 helpers.root('src/sass/include')
98 ]
99 }
100 }
101 }
102 ]
103 },
104
105 {
106 test: /\.html$/,
107 use: 'raw-loader',
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 },
114
115 {
116 test: /\.(jpg|png|gif)$/,
117 use: 'url-loader'
118 },
119
120 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
121 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
122 ]
123
124 },
125
126 plugins: [
127 new ProvidePlugin({
128 process: 'process/browser',
129 Buffer: [ 'buffer', 'Buffer' ]
130 }),
131
132 new MiniCssExtractPlugin({
133 filename: process.env.ANALYZE_BUNDLE === 'true'
134 ? '[name].css'
135 : '[name].[contenthash].css'
136 }),
137
138 new HtmlWebpackPlugin({
139 template: 'src/standalone/videos/embed.html',
140 filename: 'embed.html',
141 title: 'PeerTube',
142 chunksSortMode: 'auto',
143 inject: 'body',
144 chunks: [ 'video-embed' ],
145 minify: {
146 collapseWhitespace: true,
147 removeComments: false,
148 removeRedundantAttributes: true,
149 removeScriptTypeAttributes: true,
150 removeStyleLinkTypeAttributes: true,
151 useShortDoctype: true
152 }
153 }),
154
155 new HtmlWebpackPlugin({
156 template: '!!html-loader!src/standalone/videos/test-embed.html',
157 filename: 'test-embed.html',
158 title: 'PeerTube',
159 chunksSortMode: 'auto',
160 inject: 'body',
161 chunks: [ 'test-embed' ]
162 }),
163
164 /**
165 * Plugin LoaderOptionsPlugin (experimental)
166 *
167 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
168 */
169 new LoaderOptionsPlugin({
170 options: {
171 context: __dirname,
172 output: {
173 path: helpers.root('dist')
174 }
175 }
176 })
177 ],
178
179 optimization: {
180 minimizer: [
181 new TerserPlugin({
182 terserOptions: {
183 ecma: 6,
184 warnings: false,
185 ie8: false,
186 mangle: true,
187 compress: {
188 passes: 3,
189 pure_getters: true
190 },
191 output: {
192 ascii_only: true,
193 comments: false
194 }
195 }
196 })
197 ]
198 },
199
200 performance: {
201 maxEntrypointSize: 700000, // 600kB
202 maxAssetSize: 700000
203 },
204
205 node: {
206 global: true
207 }
208 }
209
210 return configuration
211 }