1.0.3 • Published 9 months ago

@canvases/multi-project-webpack-plugin v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

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

npm install @canvases/multi-project-webpack-plugin --save-dev

As defined in the configuration file

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 调用
        }),
    ]
};