Skip to content

Commit

Permalink
feat: added additional externals parameter to webpack plugin
Browse files Browse the repository at this point in the history
build: updated deps
  • Loading branch information
matteobruni committed Jun 29, 2023
1 parent 5dd4d18 commit 01c94e8
Show file tree
Hide file tree
Showing 21 changed files with 820 additions and 513 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"packages/*"
],
"devDependencies": {
"@nrwl/workspace": "^16.3.2",
"lerna": "^7.0.2",
"nx": "^16.3.2",
"typescript": "^5.1.3",
"@nrwl/workspace": "^16.4.0",
"lerna": "^7.1.1",
"nx": "^16.4.0",
"typescript": "^5.1.6",
"nx-cloud": "^16.0.5"
}
}
8 changes: 4 additions & 4 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
},
"dependencies": {
"@tsparticles/prettier-config": "^1.10.0",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"eslint": "^8.43.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsdoc": "^46.2.6",
"eslint-plugin-jsdoc": "^46.4.2",
"eslint-plugin-tsdoc": "^0.2.17",
"prettier": "^2.8.8",
"typescript": "^5.1.3"
"typescript": "^5.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"access": "public"
},
"dependencies": {
"typescript": "^5.1.3"
"typescript": "^5.1.6"
}
}
12 changes: 6 additions & 6 deletions packages/webpack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
"@babel/preset-env": "^7.22.5",
"@tsparticles/eslint-config": "^1.13.3",
"@tsparticles/prettier-config": "^1.10.0",
"@types/node": "^20.3.1",
"@types/node": "^20.3.2",
"@types/webpack-bundle-analyzer": "^4.6.0",
"@types/webpack-env": "^1.18.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"babel-loader": "^9.1.2",
"browserslist": "^4.21.9",
"copyfiles": "^2.4.1",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-jsdoc": "^46.2.6",
"eslint-plugin-jsdoc": "^46.4.2",
"eslint-plugin-tsdoc": "^0.2.17",
"prettier": "^2.8.8",
"rimraf": "^5.0.1",
"terser-webpack-plugin": "^5.3.9",
"typescript": "^5.1.3",
"webpack": "^5.87.0",
"typescript": "^5.1.6",
"webpack": "^5.88.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^5.1.4"
}
Expand Down
53 changes: 37 additions & 16 deletions packages/webpack-config/src/bundles/buildBundle.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
import type { ExternalData } from "../common/ExternalData";
import { getBundleEntry } from "./getBundleEntry";
import { getConfig } from "../common/getConfig";

interface BundleParams {
additionalExternals?: ExternalData[];
bundle?: boolean;
bundleName: string;
dir: string;
moduleName: string;
version: string;
}

/**
* @param moduleName -
* @param bundleName -
* @param version -
* @param dir -
* @param bundle -
* @param params -
* @returns the webpack config
*/
function loadParticlesBundle(
moduleName: string,
bundleName: string,
version: string,
dir: string,
bundle = true
): unknown {
const fixBundleName = bundleName ? `${bundleName} ` : "",
function loadParticlesBundle(params: BundleParams): unknown {
const { additionalExternals, bundle, bundleName, dir, moduleName, version } = params,
fixBundleName = bundleName ? `${bundleName} ` : "",
banner = `Author : Matteo Bruni
MIT license: https://opensource.org/licenses/MIT
Demo / Generator : https://particles.js.org/
GitHub : https://www.github.com/matteobruni/tsparticles
How to use? : Check the GitHub README
v${version}`,
minBanner = `tsParticles ${fixBundleName}v${version} by Matteo Bruni`,
configs = [getConfig(getBundleEntry(moduleName, false), version, banner, minBanner, dir, false)];
configs = [
getConfig({
entry: getBundleEntry(moduleName, false),
version,
banner,
minBanner: minBanner,
dir,
bundle: false,
additionalExternals,
}),
];

if (bundle) {
configs.push(getConfig(getBundleEntry(`${moduleName}.bundle`, true), version, banner, minBanner, dir, true));
if (bundle ?? true) {
configs.push(
getConfig({
entry: getBundleEntry(`${moduleName}.bundle`, true),
version,
banner,
minBanner: minBanner,
dir,
bundle: true,
additionalExternals,
})
);
}

return configs;
Expand Down
5 changes: 5 additions & 0 deletions packages/webpack-config/src/common/ExternalData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ExternalData {
bundle: boolean;
data: Record<string, unknown>;
name: string;
}
28 changes: 17 additions & 11 deletions packages/webpack-config/src/common/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
import type { ExternalData } from "./ExternalData";
import TerserPlugin from "terser-webpack-plugin";
import { getExternals } from "./getExternals";
import path from "path";
import webpack from "webpack";

const getConfig = (
entry: unknown,
version: string,
bannerInput: string,
minBannerInput: string,
dir: string,
bundle: boolean
): unknown => {
interface ConfigParams {
additionalExternals?: ExternalData[];
banner: string;
bundle?: boolean;
dir: string;
entry: unknown;
minBanner: string;
version: string;
}

const getConfig = (params: ConfigParams): unknown => {
const { additionalExternals, banner, bundle, dir, entry, minBanner, version } = params;

return {
entry: entry,
mode: "production",
Expand All @@ -27,7 +33,7 @@ const getConfig = (
resolve: {
extensions: [".js", ".json"],
},
externals: getExternals(bundle),
externals: getExternals({ bundle, additionalExternals }),
module: {
rules: [
{
Expand All @@ -43,11 +49,11 @@ const getConfig = (
__VERSION__: JSON.stringify(version),
}),
new webpack.BannerPlugin({
banner: bannerInput,
banner,
exclude: /\.min\.js$/,
}),
new webpack.BannerPlugin({
banner: minBannerInput,
banner: minBanner,
include: /\.min\.js$/,
}),
new webpack.ProgressPlugin(),
Expand Down
Loading

0 comments on commit 01c94e8

Please sign in to comment.