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