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