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