]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.video-embed.js
fe40194cf3a010fd5c9b35262e8865ecc1f2f27e
[github/Chocobozzz/PeerTube.git] / client / config / webpack.video-embed.js
1 const helpers = require('./helpers')
2
3 const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
4 const HtmlWebpackPlugin = require('html-webpack-plugin')
5 const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
6 const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
7 const ExtractTextPlugin = require('extract-text-webpack-plugin')
8 const PurifyCSSPlugin = require('purifycss-webpack')
9
10 module.exports = function (options) {
11 const isProd = options && options.env === 'production'
12
13 const configuration = {
14 entry: {
15 'video-embed': './src/standalone/videos/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'), helpers.root('node_modules') ]
27 },
28
29 output: {
30 path: helpers.root('dist/standalone/videos'),
31 filename: '[name].[hash].bundle.js',
32 sourceMapFilename: '[file].map',
33 chunkFilename: '[id].chunk.js',
34 publicPath: '/client/standalone/videos/'
35 },
36
37 module: {
38
39 rules: [
40 {
41 test: /\.ts$/,
42 use: [
43 {
44 loader: 'awesome-typescript-loader',
45 options: {
46 configFileName: 'tsconfig.webpack.json',
47 useCache: !isProd
48 }
49 }
50 ],
51 exclude: [/\.(spec|e2e)\.ts$/]
52 },
53
54 {
55 test: /\.(sass|scss)$/,
56 use: ExtractTextPlugin.extract({
57 fallback: 'style-loader',
58 use: [
59 {
60 loader: 'css-loader',
61 options: {
62 sourceMap: true,
63 importLoaders: 1
64 }
65 },
66 'resolve-url-loader',
67 {
68 loader: 'sass-loader',
69 options: {
70 sourceMap: true
71 }
72 },
73 {
74 loader: 'sass-resources-loader',
75 options: {
76 resources: [
77 helpers.root('src/sass/_variables.scss')
78 ]
79 }
80 }
81 ]
82 })
83 },
84
85 {
86 test: /\.html$/,
87 use: 'raw-loader',
88 exclude: [
89 helpers.root('src/index.html'),
90 helpers.root('src/standalone/videos/embed.html')
91 ]
92 },
93
94 {
95 test: /\.(jpg|png|gif)$/,
96 use: 'url-loader'
97 },
98
99 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
100 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
101 ]
102
103 },
104
105 plugins: [
106 new ExtractTextPlugin({
107 filename: '[name].[contenthash].css'
108 }),
109
110 new PurifyCSSPlugin({
111 paths: [ helpers.root('src/standalone/videos/embed.ts') ],
112 purifyOptions: {
113 minify: true,
114 whitelist: [ '*vjs*', '*video-js*' ]
115 }
116 }),
117
118 new CheckerPlugin(),
119
120 new HtmlWebpackPlugin({
121 template: 'src/standalone/videos/embed.html',
122 filename: 'embed.html',
123 title: 'PeerTube',
124 chunksSortMode: 'dependency',
125 inject: 'body'
126 })
127 ],
128
129 node: {
130 global: true,
131 crypto: 'empty',
132 fs: 'empty',
133 process: true,
134 module: false,
135 clearImmediate: false,
136 setImmediate: false
137 }
138 }
139
140 if (isProd) {
141 configuration.module.rules.push(
142 {
143 test: /junk\/index\.js$/,
144 // exclude: /(node_modules|bower_components)/,
145 use: {
146 loader: 'babel-loader',
147 options: {
148 presets: [ 'env' ]
149 }
150 }
151 }
152 )
153
154 configuration.plugins.push(
155 new UglifyJsPlugin({
156 beautify: false,
157 output: {
158 comments: false
159 }, // prod
160 mangle: {
161 screw_ie8: true
162 }, // prod
163 compress: {
164 screw_ie8: true,
165 warnings: false,
166 conditionals: true,
167 unused: true,
168 comparisons: true,
169 sequences: true,
170 dead_code: true,
171 evaluate: true,
172 if_return: true,
173 join_vars: true,
174 negate_iife: false // we need this for lazy v8
175 }
176 }),
177
178 new HashedModuleIdsPlugin()
179 )
180 }
181
182 return configuration
183 }