Skip to content

Commit

Permalink
Add new Webpack config to create a modern and a legacy build
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Jan 8, 2025
1 parent 63e2df6 commit 15a2bf1
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 159 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
76 changes: 0 additions & 76 deletions build/webpack.base.cjs

This file was deleted.

64 changes: 0 additions & 64 deletions build/webpack.prod.cjs

This file was deleted.

44 changes: 44 additions & 0 deletions build/webpack/common/webpack.common.base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const pkg = require('../../../package.json');

const commonBaseConfig = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.(js)$/,
exclude: [/core-js/],
use: [
{
loader: 'string-replace-loader',
options: {
search: '__VERSION__',
replace: pkg.version,
},
}
],
},
],
},
resolve: {
fallback: {
stream: require.resolve('stream-browserify'),
},
},
}

const prodEntries = {
'dash.all': './index.js',
'dash.mss': './src/mss/index.js',
'dash.mediaplayer': './index_mediaplayerOnly.js',
'dash.protection': './src/streaming/protection/Protection.js',
'dash.reporting': './src/streaming/metrics/MetricsReporting.js',
'dash.offline': './src/offline/index.js'
}

const devEntries = {
'dash.all': './index.js',
'dash.mss': './src/mss/index.js',
'dash.offline': './src/offline/index.js'
}

module.exports = { commonBaseConfig, prodEntries, devEntries };
54 changes: 54 additions & 0 deletions build/webpack/common/webpack.common.prod.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const EsLintWebpackPlugin = require('eslint-webpack-plugin');
const { prodEntries } = require('../common/webpack.common.base.cjs');

const plugins = [
new EsLintWebpackPlugin({
configType: 'flat',
files: [
'src/**/*.js',
'test/unit/mocks/*.js',
'test/unit/test/**/*.js'
]
})
]

const configCommonDebugProdUmd = {
mode: 'development',
entry: prodEntries,
output: {
filename: '[name].debug.js'
}
};

const configCommonMinProdUmd = {
mode: 'production',
entry: prodEntries,
output: {
filename: '[name].min.js'
},
performance: { hints: false },
plugins
};

const configCommonDebugProdEsm = {
mode: 'development',
entry: prodEntries,
output: {
filename: '[name].debug.esm.js'
}
};

const configCommonMinProdEsm = {
mode: 'production',
entry: prodEntries,
output: {
filename: '[name].min.esm.js'
},
optimization: {
usedExports: false,
},
performance: { hints: false },
plugins
};

module.exports = { configCommonDebugProdEsm, configCommonMinProdEsm, configCommonDebugProdUmd, configCommonMinProdUmd };
56 changes: 56 additions & 0 deletions build/webpack/legacy/webpack.legacy.base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const path = require('path');
const { merge } = require('webpack-merge');
const { commonBaseConfig } = require('../common/webpack.common.base.cjs');

const legacyConfig = merge(commonBaseConfig, {
target: ['web', 'es5']
});

legacyConfig.module.rules[0].use.push({
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
targets: {
ie: '11',
},
corejs: '3.39.0',
}
],
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-parameters'
],
},
},)

const umdConfig = merge(legacyConfig, {
output: {
path: path.resolve(__dirname, '../../../dist/legacy/umd'),
publicPath: '/dist/legacy/umd/',
library: 'dashjs',
libraryTarget: 'umd',
libraryExport: 'default'
},
});

const esmConfig = merge(legacyConfig, {
experiments: {
outputModule: true
},
output: {
path: path.resolve(__dirname, '../../../dist/legacy/esm'),
publicPath: '/dist/legacy/esm/',
library: {
type: 'module',
},
libraryExport: 'default',
},
});

module.exports = { umdConfig, esmConfig };
18 changes: 18 additions & 0 deletions build/webpack/legacy/webpack.legacy.prod.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { merge } = require('webpack-merge');
const { umdConfig, esmConfig } = require('./webpack.legacy.base.cjs');
const {
configCommonDebugProdEsm,
configCommonMinProdEsm,
configCommonDebugProdUmd,
configCommonMinProdUmd
} = require('../common/webpack.common.prod.cjs');

const configLegacyDebugUmd = merge(umdConfig, configCommonDebugProdUmd);

const configLegacyMinUmd = merge(umdConfig, configCommonMinProdUmd);

const configLegacyDebugEsm = merge(esmConfig, configCommonDebugProdEsm);

const configLegacyMinEsm = merge(esmConfig, configCommonMinProdEsm);

module.exports = [configLegacyDebugUmd, configLegacyMinUmd, configLegacyDebugEsm, configLegacyMinEsm];
53 changes: 53 additions & 0 deletions build/webpack/modern/webpack.modern.base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const path = require('path');
const { merge } = require('webpack-merge');
const { commonBaseConfig } = require('../common/webpack.common.base.cjs');

const modernConfig = merge(commonBaseConfig, {
target: ['browserslist']
});

modernConfig.module.rules[0].use.push({
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: '3.39.0',
}
],
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-parameters'
],
},
},)

const umdConfig = merge(modernConfig, {
output: {
path: path.resolve(__dirname, '../../../dist/modern/umd'),
publicPath: '/dist/modern/umd/',
library: 'dashjs',
libraryTarget: 'umd',
libraryExport: 'default'
},
});

const esmConfig = merge(modernConfig, {
experiments: {
outputModule: true
},
output: {
path: path.resolve(__dirname, '../../../dist/modern/esm'),
publicPath: '/dist/modern/esm/',
library: {
type: 'module',
},
libraryExport: 'default',
},
});

module.exports = { umdConfig, esmConfig };
Loading

0 comments on commit 15a2bf1

Please sign in to comment.