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