UNPKG

@canvases/multi-project-webpack-plugin

Version:

"A Webpack plugin that enables multi-project configuration support, allowing different code blocks to be compiled or executed based on configuration files.

42 lines (35 loc) 1.61 kB
# Multi Project Webpack Plugin ## Description `multi-project-webpack-plugin` is a Webpack plugin that enables multi-project configuration support. It allows you to define different build or runtime code blocks for different project scenarios based on a configuration file. ## Features - 🏗 **Multi-Project Support**: Customize builds for different projects using configuration files. - 🎯 **Conditional Compilation**: Compile only the necessary code blocks for a specific project. - ⚡ **Flexible Configuration**: Supports JSON/YAML configuration for easy customization. - 🚀 **Enhances Webpack Builds**: Helps streamline multi-project workflows by reducing redundant code. ## Installation ```sh npm install @canvases/multi-project-webpack-plugin --save-dev ```` ### As defined in the configuration file ```js const path = require('path'); const MultiProjectWebpackPlugin = require('@canvases/multi-project-webpack-plugin'); module.exports = { resolve: { alias: { '@': path.resolve(__dirname, 'src') // “@” 指向项目根目录下的 src 文件夹 } }, plugins: [ new webpack.DefinePlugin({ 'process.env.PLATFORM': JSON.stringify(process.env.PLATFORM) }), // // 自定义条件编译插件 new MultiProjectWebpackPlugin({ platform: process.env.PLATFORM, entryPath: './manifest.json', exportPath: '@/config.js', // 使用 alias 指向配置文件,并在项目中引入, 可用window.CODE_CONFIG 调用 }), ] }; ```