]>
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') |
662351e6 | 6 | const ProvidePlugin = require('webpack/lib/ProvidePlugin') |
4f926722 | 7 | const MiniCssExtractPlugin = require('mini-css-extract-plugin') |
202e7223 | 8 | |
7bfd1b1e | 9 | module.exports = function () { |
202e7223 C |
10 | const configuration = { |
11 | entry: { | |
99941732 WL |
12 | 'video-embed': './src/standalone/videos/embed.ts', |
13 | 'player': './src/standalone/player/player.ts', | |
14 | 'test-embed': './src/standalone/videos/test-embed.ts' | |
202e7223 C |
15 | }, |
16 | ||
17 | resolve: { | |
18 | /* | |
19 | * An array of extensions that should be used to resolve modules. | |
20 | * | |
21 | * See: http://webpack.github.io/docs/configuration.html#resolve-extensions | |
22 | */ | |
23 | extensions: [ '.ts', '.js', '.json', '.scss' ], | |
24 | ||
72aa835e | 25 | modules: [ helpers.root('src'), 'node_modules' ], |
6cca7360 | 26 | |
a77c5ff3 C |
27 | symlinks: true, |
28 | ||
6cca7360 | 29 | alias: { |
71ab65d0 | 30 | 'video.js$': path.resolve('node_modules/video.js/core.js'), |
134006b0 | 31 | 'hls.js$': path.resolve('node_modules/hls.js/dist/hls.light.js'), |
4504f09f | 32 | '@root-helpers': path.resolve('src/root-helpers'), |
583eb04b | 33 | '@shared/models': path.resolve('../shared/models'), |
bd45d503 | 34 | '@shared/core-utils': path.resolve('../shared/core-utils') |
662351e6 C |
35 | }, |
36 | ||
37 | fallback: { | |
38 | fs: [ path.resolve('src/shims/noop.ts') ], | |
39 | http: [ path.resolve('src/shims/http.ts') ], | |
40 | https: [ path.resolve('src/shims/https.ts') ], | |
41 | path: [ path.resolve('src/shims/path.ts') ], | |
134006b0 | 42 | stream: [ path.resolve('src/shims/stream.ts') ], |
662351e6 | 43 | crypto: [ path.resolve('src/shims/noop.ts') ] |
6cca7360 | 44 | } |
202e7223 C |
45 | }, |
46 | ||
47 | output: { | |
48 | path: helpers.root('dist/standalone/videos'), | |
a3b5e78a C |
49 | |
50 | filename: process.env.ANALYZE_BUNDLE === 'true' | |
51 | ? '[name].bundle.js' | |
662351e6 | 52 | : '[name].[contenthash].bundle.js', |
a3b5e78a | 53 | |
202e7223 | 54 | sourceMapFilename: '[file].map', |
031ea8ef C |
55 | |
56 | chunkFilename: process.env.ANALYZE_BUNDLE === 'true' | |
57 | ? '[name].chunk.js' | |
662351e6 | 58 | : '[id].[contenthash].chunk.js', |
031ea8ef | 59 | |
202e7223 C |
60 | publicPath: '/client/standalone/videos/' |
61 | }, | |
62 | ||
d1a63fc7 | 63 | devtool: process.env.NODE_ENV === 'production' ? false : 'source-map', |
f6a7c82c | 64 | |
202e7223 C |
65 | module: { |
66 | ||
67 | rules: [ | |
68 | { | |
69 | test: /\.ts$/, | |
70 | use: [ | |
71 | { | |
583eb04b | 72 | loader: 'ts-loader', |
202e7223 | 73 | options: { |
42b40636 | 74 | configFile: helpers.root('src/standalone/videos/tsconfig.json') |
202e7223 C |
75 | } |
76 | } | |
583eb04b | 77 | ] |
202e7223 | 78 | }, |
6527eb0c | 79 | { |
4ce5f50c | 80 | test: /\.m?js$/, |
6527eb0c C |
81 | use: [ |
82 | { | |
83 | loader: 'babel-loader', | |
84 | options: { | |
85 | presets: [ | |
86 | [ | |
87 | '@babel/preset-env', { | |
88 | targets: 'last 1 Chrome version, last 2 Edge major versions, Firefox ESR, Safari >= 11, ios_saf >= 11' | |
89 | } | |
90 | ] | |
91 | ] | |
92 | } | |
93 | } | |
94 | ] | |
95 | }, | |
202e7223 C |
96 | |
97 | { | |
98 | test: /\.(sass|scss)$/, | |
4f926722 C |
99 | use: [ |
100 | MiniCssExtractPlugin.loader, | |
101 | ||
102 | { | |
103 | loader: 'css-loader', | |
104 | options: { | |
105 | sourceMap: true, | |
106 | importLoaders: 1 | |
107 | } | |
108 | }, | |
109 | ||
110 | { | |
111 | loader: 'sass-loader', | |
112 | options: { | |
113 | sassOptions: { | |
202e7223 | 114 | sourceMap: true, |
4f926722 C |
115 | includePaths: [ |
116 | helpers.root('src/sass/include') | |
117 | ] | |
202e7223 C |
118 | } |
119 | } | |
4f926722 C |
120 | } |
121 | ] | |
202e7223 C |
122 | }, |
123 | ||
124 | { | |
125 | test: /\.html$/, | |
202e7223 C |
126 | exclude: [ |
127 | helpers.root('src/index.html'), | |
99941732 WL |
128 | helpers.root('src/standalone/videos/embed.html'), |
129 | helpers.root('src/standalone/videos/test-embed.html') | |
adb8809d C |
130 | ], |
131 | type: 'asset/source' | |
202e7223 C |
132 | }, |
133 | ||
134 | { | |
adb8809d C |
135 | test: /\.(jpg|png|gif|svg)$/, |
136 | type: 'asset' | |
202e7223 C |
137 | }, |
138 | ||
adb8809d C |
139 | { |
140 | test: /\.(ttf|eot|woff2?)$/, | |
141 | type: 'asset' | |
142 | } | |
202e7223 C |
143 | ] |
144 | ||
145 | }, | |
146 | ||
147 | plugins: [ | |
662351e6 C |
148 | new ProvidePlugin({ |
149 | process: 'process/browser', | |
150 | Buffer: [ 'buffer', 'Buffer' ] | |
151 | }), | |
152 | ||
4f926722 | 153 | new MiniCssExtractPlugin({ |
a3b5e78a C |
154 | filename: process.env.ANALYZE_BUNDLE === 'true' |
155 | ? '[name].css' | |
662351e6 | 156 | : '[name].[contenthash].css' |
202e7223 C |
157 | }), |
158 | ||
202e7223 C |
159 | new HtmlWebpackPlugin({ |
160 | template: 'src/standalone/videos/embed.html', | |
161 | filename: 'embed.html', | |
162 | title: 'PeerTube', | |
4adebd51 | 163 | chunksSortMode: 'auto', |
99941732 | 164 | inject: 'body', |
662351e6 | 165 | chunks: [ 'video-embed' ], |
2564d97e | 166 | minify: { |
167 | collapseWhitespace: true, | |
168 | removeComments: false, | |
169 | removeRedundantAttributes: true, | |
170 | removeScriptTypeAttributes: true, | |
171 | removeStyleLinkTypeAttributes: true, | |
172 | useShortDoctype: true | |
173 | } | |
99941732 WL |
174 | }), |
175 | ||
176 | new HtmlWebpackPlugin({ | |
177 | template: '!!html-loader!src/standalone/videos/test-embed.html', | |
178 | filename: 'test-embed.html', | |
179 | title: 'PeerTube', | |
4adebd51 | 180 | chunksSortMode: 'auto', |
99941732 | 181 | inject: 'body', |
662351e6 | 182 | chunks: [ 'test-embed' ] |
202e7223 C |
183 | }) |
184 | ], | |
185 | ||
ae04a0ce C |
186 | optimization: { |
187 | minimizer: [ | |
188 | new TerserPlugin({ | |
189 | terserOptions: { | |
190 | ecma: 6, | |
191 | warnings: false, | |
192 | ie8: false, | |
2873f00b | 193 | safari10: true, |
ae04a0ce C |
194 | mangle: true, |
195 | compress: { | |
196 | passes: 3, | |
197 | pure_getters: true | |
198 | }, | |
199 | output: { | |
200 | ascii_only: true, | |
201 | comments: false | |
202 | } | |
203 | } | |
204 | }) | |
205 | ] | |
206 | }, | |
207 | ||
fc9e6624 | 208 | performance: { |
efda99c3 C |
209 | maxEntrypointSize: 700000, // 600kB |
210 | maxAssetSize: 700000 | |
fc9e6624 C |
211 | }, |
212 | ||
202e7223 | 213 | node: { |
662351e6 | 214 | global: true |
202e7223 C |
215 | } |
216 | } | |
217 | ||
202e7223 C |
218 | return configuration |
219 | } |