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