Skip to content

Commit

Permalink
build: added plugins to webpack plugin package
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed Sep 23, 2021
1 parent 5c4e3de commit f4ba397
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 106 deletions.
3 changes: 2 additions & 1 deletion plugins/infection/package.json
Expand Up @@ -69,7 +69,8 @@
"typescript": "^4.4.2",
"webpack": "^5.50.0",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^4.8.0"
"webpack-cli": "^4.8.0",
"webpack-tsparticles-plugin": "^1.0.0"
},
"dependencies": {
"tsparticles-engine": "^1.35.1"
Expand Down
104 changes: 2 additions & 102 deletions plugins/infection/webpack.config.js
@@ -1,104 +1,4 @@
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { loadParticlesPlugin } = require("webpack-tsparticles-plugin");
const version = require("./package.json").version;

const getEntry = (name) => {
const obj = {};

obj[`tsparticles.plugin.${name}`] = "./dist/index.js";
obj[`tsparticles.plugin.${name}.min`] = "./dist/index.js";

return obj;
};

const getConfig = (entry, banner, minBanner, dir) => {
return {
entry: entry,
output: {
path: path.resolve(dir, "dist"),
filename: "[name].js",
libraryTarget: "umd",
globalObject: "this"
},
resolve: {
extensions: [ ".js", ".json" ]
},
externals: [
{
tsparticles: {
commonjs: "tsparticles",
commonjs2: "tsparticles",
amd: "tsparticles",
root: "window"
},
"tsparticles-engine": {
commonjs: "tsparticles-engine",
commonjs2: "tsparticles-engine",
amd: "tsparticles-engine",
root: "window"
},
"tsparticles-slim": {
commonjs: "tsparticles-slim",
commonjs2: "tsparticles-slim",
amd: "tsparticles-slim",
root: "window"
},
}
],
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
plugins: [
new webpack.BannerPlugin({
banner: banner,
exclude: /\.min\.js$/
}),
new webpack.BannerPlugin({
banner: minBanner,
include: /\.min\.js$/
}),
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: "static",
exclude: /\.min\.js$/,
reportFilename: `report.html`
})
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /\.min\.js$/,
terserOptions: {
output: {
comments: minBanner
}
},
extractComments: false
})
]
}
};
};

const 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}`;

const minBanner = `tsParticles Infection Plugin v${version} by Matteo Bruni`;

module.exports = [
getConfig(getEntry("infection"), banner, minBanner, __dirname)
];
module.exports = loadParticlesPlugin("infection", "Infection", version, __dirname);
17 changes: 17 additions & 0 deletions utils/webpack/plugins/buildPlugin.js
@@ -0,0 +1,17 @@
const {getPluginEntry} = require("./getPluginEntry");
const {getConfig} = require("../common/getConfig");

function loadParticlesPlugin(moduleName, pluginName, version, dir) {
const 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 ${pluginName} Preset v${version} by Matteo Bruni`;

return [
getConfig(getPluginEntry(moduleName, false), banner, minBanner, dir, false)
];
}

module.exports = {loadParticlesPlugin};
9 changes: 9 additions & 0 deletions utils/webpack/plugins/getPluginEntry.js
@@ -0,0 +1,9 @@
const {getEntry} = require("../common/getEntry");

getPluginEntry = (name, bundle) => {
return getEntry("plugin", name, bundle);
}

module.exports = {
getPluginEntry
};
4 changes: 2 additions & 2 deletions utils/webpack/shapes/buildShape.js
@@ -1,13 +1,13 @@
const {getShapeEntry} = require("./getShapeEntry");
const {getConfig} = require("../common/getConfig");

function loadParticlesShape(moduleName, presetName, version, dir) {
function loadParticlesShape(moduleName, shapeName, version, dir) {
const 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 ${presetName} Shape v${version} by Matteo Bruni`;
v${version}`, minBanner = `tsParticles ${shapeName} Shape v${version} by Matteo Bruni`;

return [
getConfig(getShapeEntry(moduleName, false), banner, minBanner, dir, false)
Expand Down
4 changes: 3 additions & 1 deletion utils/webpack/webpack-tsparticles.js
@@ -1,7 +1,9 @@
const {loadParticlesPreset} = require("./presets/buildPreset");
const {loadParticlesShape} = require("./shapes/buildShape");
const {loadParticlesPlugin} = require("./plugins/buildPlugin");

module.exports = {
loadParticlesPreset,
loadParticlesShape
loadParticlesShape,
loadParticlesPlugin
};

0 comments on commit f4ba397

Please sign in to comment.