plugin-preloader
v1.0.0
Published
This library dynamically preloads and installs Babel and ESLint plugins and presets based on your configuration, streamlining the build process without the need to include them as dependencies in your project.
Downloads
11
Readme
plugin-preloader
This library offers a method for preloading Babel and ESLint packages according to their configurations, ensuring that all necessary packages are installed before initiating any build process. This plugin is designed to dynamically install plugins without the need to include them in your project's dependencies, thus streamlining the setup process.
Features
- Automatically install Babel and ESLint packages based on their configuration files.
- Supports both latest and specific package versions.
Installation
To install the library, run the following command:
npm install --save-dev plugin-preloader
Usage
The preload
function can operate effectively with standard Babel and ESLint configurations, ensuring that each plugin, preset, parser, or extend is processed and installed at the most recent version.
To designate a specific version rather than the latest for Babel plugins and presets, you can use the fourth element in the plugin/preset definition array item, bypassing the second and third elements - ["@babel/preset-react", undefined, undefined, "7.0.0"]
.
To designate the required version for ESLint plugins, extends, and parsers, use an array instead of a string and place the desired version as the second element in the array - ["plugin:@typescript-eslint/recommended", "3.0.0"]
.
const sampleBabelConfig: BabelConfig = {
presets: [["@babel/preset-react", undefined, undefined, "7.0.0"]],
plugins: [
"@babel/plugin-transform-runtime",
["@babel/plugin-proposal-decorators", {}],
["@babel/plugin-proposal-private-methods", undefined, undefined, "8.0.0"],
],
env: {
test: {
presets: [["@babel/preset-env", "7.0.0"]],
},
},
};
const sampleEslintConfig: ESLintConfig = {
extends: [
"eslint:recommended",
["plugin:react/recommended", "6.0.0"],
"plugin:@typescript-eslint/recommended",
],
plugins: ["abcsize", ["react-hooks", "2.4.0"]],
parser: ["@typescript-eslint/parser", "3.4.5"],
};
Preload
const preload = require("plugin-preloader");
preload({ babel: sampleBabelConfig, eslint: sampleEslintConfig });
In addition, we have provided a sample project in the example folder.
API
syncPreload({ babel, eslint })
- Parameters:
- Object with the following properties:
babel
: BabelConfig object (optional)eslint
: ESLintConfig object (optional)
- Object with the following properties:
- Returns:
void
- Description: Installs the required packages synchronously based on the Babel and ESLint configurations.
Known Issues
Incompatibility with
pnpm
package manager: This project may not function correctly with thepnpm
package manager. It is recommended to usenpm
oryarn
for better compatibility and a smoother experiencePossible disruption of existing dependencies: Due to the complex nature of the installation process, this project could potentially break already installed dependencies. As a result, your project might not build as expected and may require reinstalling the node modules
Restoring the initial node modules structure: If you encounter issues with your node modules, you can execute the npm prune or yarn install commands to restore the initial node modules structure and resolve any discrepancies. This will help ensure your project builds correctly after using the library
Babel plugins/presets definition methods: This project supports only string as the first item in the Babel plugin/preset definition array. If you use a different method, the library will not be able to install the required packages
Lack of support for plugins/presets: This project has limited support for Babel/ESLint plugins and presets. If you use a plugin/preset not supported by the library, it will not be installed. The supported Babel plugins and presets can be found and added here. The supported ESLint plugins, extends, and parsers can be found and added here
Development
In order to start contributing to plugin-preloader
, you can follow these steps: CONTRIBUTING.md
CHANGELOG
If you want to see what changed between versions: CHANGELOG.md