WeChat Mini Program Bundler

0.1.20 · active · verified Tue Apr 21

weapp-minipack is a JavaScript bundler specifically designed for WeChat mini-programs, with a strong emphasis on TypeScript support. Currently at version 0.1.20, it provides both a command-line interface (CLI) for quick project setup and a programmatic API for more custom build workflows. The tool aims to simplify the development process for mini-programs by handling TypeScript compilation, asset copying, and offering a robust plugin system for extending its functionality, such as WXSS minification. Its release cadence is likely irregular given its early stage of development, but it actively integrates with standard tools like `esbuild` for performance. A key differentiator is its focus on the unique structure and requirements of WeChat mini-programs, providing specific configurations like `miniprogramProjectPath` and direct integration for environment variable injection.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic usage to initialize and run the bundler with a custom configuration, including a basic plugin for WXSS processing.

import { Entry } from 'weapp-minipack';
import path from 'path';

// Define your minipack configuration
const minipackConfig = {
  watchEntry: path.resolve(__dirname, 'src'), // Source directory for mini-program files
  tsConfigPath: path.resolve(__dirname, 'tsconfig.json'), // Path to your TypeScript config
  outDir: path.resolve(__dirname, 'build'), // Output directory for compiled files
  isWatch: false, // Set to true to enable watch mode for development
  miniprogramProjectPath: path.resolve(__dirname, 'project.config.json'),
  plugins: [
    {
      test: /.*\.(wxss)$/,
      action: ({ data }) => {
        // Example: simple CSS minification or just passing through
        return data.replace(/\s+/g, ' ').trim();
      },
    },
  ],
};

// Create an instance of Entry with your configuration
// For a production build, ensure isWatch is false.
const bundler = new Entry({ 
  config: minipackConfig 
});

// Initialize and start the bundling process
bundler.init().start()
  .then(() => console.log('Mini-program build successful!'))
  .catch(error => console.error('Mini-program build failed:', error));

view raw JSON →