]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/webpack/webpack.video-embed.js
403a65930b56a13daed5fe964eab5c65a8316fcd
[github/Chocobozzz/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 UglifyJsPlugin = require('uglifyjs-webpack-plugin')
7 const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
8 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
9 const ExtractTextPlugin = require('extract-text-webpack-plugin')
10 const PurifyCSSPlugin = require('purifycss-webpack')
11
12 module.exports = function () {
13 const isProd = process.env.NODE_ENV === 'production'
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
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 }
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
43 // devtool: 'source-map',
44
45 module: {
46
47 rules: [
48 {
49 test: /\.ts$/,
50 use: [
51 {
52 loader: 'awesome-typescript-loader',
53 options: {
54 configFileName: 'tsconfig.json'
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: {
77 sourceMap: true,
78 includePaths: [
79 helpers.root('src/sass/include')
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({
109 filename: '[name].[hash].css'
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'
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 }
142 })
143 ],
144
145 performance: {
146 maxEntrypointSize: 700000, // 600kB
147 maxAssetSize: 700000
148 },
149
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) {
162 configuration.plugins.push(
163 new UglifyJsPlugin({
164 uglifyOptions: {
165 ecma: 6,
166 warnings: false,
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 }
177 }
178 }),
179
180 new HashedModuleIdsPlugin()
181 )
182 }
183
184 return configuration
185 }