Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: added plugins to webpack plugin package
- Loading branch information
1 parent
5c4e3de
commit f4ba397
Showing
6 changed files
with
35 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const {getEntry} = require("../common/getEntry"); | ||
|
||
getPluginEntry = (name, bundle) => { | ||
return getEntry("plugin", name, bundle); | ||
} | ||
|
||
module.exports = { | ||
getPluginEntry | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; |