1
0
Fork 0
peertube/client/webpack/webpack.video-embed.js
Chocobozzz 3a4992633e
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:

 * Server can be faster at startup because imports() are async and we can
   easily lazy import big modules
 * Angular doesn't seem to support ES import (with .js extension), so we
   had to correctly organize peertube into a monorepo:
    * Use yarn workspace feature
    * Use typescript reference projects for dependencies
    * Shared projects have been moved into "packages", each one is now a
      node module (with a dedicated package.json/tsconfig.json)
    * server/tools have been moved into apps/ and is now a dedicated app
      bundled and published on NPM so users don't have to build peertube
      cli tools manually
    * server/tests have been moved into packages/ so we don't compile
      them every time we want to run the server
 * Use isolatedModule option:
   * Had to move from const enum to const
     (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
   * Had to explictely specify "type" imports when used in decorators
 * Prefer tsx (that uses esbuild under the hood) instead of ts-node to
   load typescript files (tests with mocha or scripts):
     * To reduce test complexity as esbuild doesn't support decorator
       metadata, we only test server files that do not import server
       models
     * We still build tests files into js files for a faster CI
 * Remove unmaintained peertube CLI import script
 * Removed some barrels to speed up execution (less imports)
2023-08-11 15:02:33 +02:00

218 lines
5.1 KiB
JavaScript

const helpers = require('./helpers')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const ProvidePlugin = require('webpack/lib/ProvidePlugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = function () {
const configuration = {
entry: {
'video-embed': './src/standalone/videos/embed.ts',
'player': './src/standalone/embed-player-api/player.ts',
'test-embed': './src/standalone/videos/test-embed.ts'
},
resolve: {
/*
* An array of extensions that should be used to resolve modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/
extensions: [ '.ts', '.js', '.json', '.scss' ],
modules: [ helpers.root('src'), 'node_modules' ],
symlinks: true,
alias: {
'video.js$': path.resolve('node_modules/video.js/core.js'),
'hls.js$': path.resolve('node_modules/hls.js/dist/hls.light.js'),
'@root-helpers': path.resolve('src/root-helpers')
},
fallback: {
fs: [ path.resolve('src/shims/noop.ts') ],
path: [ path.resolve('src/shims/path.ts') ],
crypto: [ path.resolve('src/shims/noop.ts') ]
}
},
output: {
path: helpers.root('dist/standalone/videos'),
filename: process.env.ANALYZE_BUNDLE === 'true'
? '[name].bundle.js'
: '[name].[contenthash].bundle.js',
sourceMapFilename: '[file].map',
chunkFilename: process.env.ANALYZE_BUNDLE === 'true'
? '[name].chunk.js'
: '[id].[contenthash].chunk.js',
publicPath: '/client/standalone/videos/'
},
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
module: {
rules: [
{
test: /\.ts$/,
use: [
getBabelLoader(),
{
loader: 'ts-loader',
options: {
configFile: helpers.root('src/standalone/videos/tsconfig.json')
}
}
]
},
{
test: /\.m?js$/,
use: [ getBabelLoader() ]
},
{
test: /\.(sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'sass-loader',
options: {
sassOptions: {
sourceMap: true,
includePaths: [
helpers.root('src/sass/include')
]
}
}
}
]
},
{
test: /\.html$/,
exclude: [
helpers.root('src/index.html'),
helpers.root('src/standalone/videos/embed.html'),
helpers.root('src/standalone/videos/test-embed.html')
],
type: 'asset/source'
},
{
test: /\.(jpg|png|gif|svg)$/,
type: 'asset'
},
{
test: /\.(ttf|eot|woff2?)$/,
type: 'asset'
}
]
},
plugins: [
new ProvidePlugin({
process: 'process/browser',
Buffer: [ 'buffer', 'Buffer' ]
}),
new MiniCssExtractPlugin({
filename: process.env.ANALYZE_BUNDLE === 'true'
? '[name].css'
: '[name].[contenthash].css'
}),
new HtmlWebpackPlugin({
template: 'src/standalone/videos/embed.html',
filename: 'embed.html',
title: 'PeerTube',
chunksSortMode: 'auto',
inject: 'body',
chunks: [ 'video-embed' ],
minify: {
collapseWhitespace: true,
removeComments: false,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
}
}),
new HtmlWebpackPlugin({
template: '!!html-loader!src/standalone/videos/test-embed.html',
filename: 'test-embed.html',
title: 'PeerTube',
chunksSortMode: 'auto',
inject: 'body',
chunks: [ 'test-embed' ]
})
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 6,
warnings: false,
ie8: false,
safari10: false,
mangle: true,
compress: {
passes: 3,
pure_getters: true
},
output: {
ascii_only: true,
comments: false
}
}
})
]
},
performance: {
maxEntrypointSize: 700000, // 600kB
maxAssetSize: 700000
},
node: {
global: true
}
}
return configuration
}
function getBabelLoader () {
return {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env', {
targets: 'last 1 Chrome version, last 2 Edge major versions, Firefox ESR, Safari >= 12, ios_saf >= 12'
}
]
]
}
}
}