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