{"id":15926,"library":"weapp-minipack","title":"WeChat Mini Program Bundler","description":"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.","status":"active","version":"0.1.20","language":"javascript","source_language":"en","source_url":"https://github.com/IchliebedichZhu/weapp-minipack","tags":["javascript","wechat","miniprogram","typescript"],"install":[{"cmd":"npm install weapp-minipack","lang":"bash","label":"npm"},{"cmd":"yarn add weapp-minipack","lang":"bash","label":"yarn"},{"cmd":"pnpm add weapp-minipack","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The documentation primarily uses CommonJS `require`, but the library ships TypeScript types, implying ESM usage is expected in modern projects. Ensure your project is configured for ESM or use `require` for CJS.","wrong":"const { Entry } = require('weapp-minipack');","symbol":"Entry","correct":"import { Entry } from 'weapp-minipack';"},{"note":"The README incorrectly shows `require('weapp_minipack')` for the plugin; the correct import should be from the main `weapp-minipack` package.","wrong":"const { minifierStyle } = require('weapp_minipack');","symbol":"minifierStyle","correct":"import { minifierStyle } from 'weapp-minipack';"},{"note":"The primary CLI usage involves globally installing the package and pointing to a configuration file. There's no direct import for the CLI itself.","symbol":"CLI usage","correct":"weapp-minipack -c ./minipack.config.js"}],"quickstart":{"code":"import { Entry } from 'weapp-minipack';\nimport path from 'path';\n\n// Define your minipack configuration\nconst minipackConfig = {\n  watchEntry: path.resolve(__dirname, 'src'), // Source directory for mini-program files\n  tsConfigPath: path.resolve(__dirname, 'tsconfig.json'), // Path to your TypeScript config\n  outDir: path.resolve(__dirname, 'build'), // Output directory for compiled files\n  isWatch: false, // Set to true to enable watch mode for development\n  miniprogramProjectPath: path.resolve(__dirname, 'project.config.json'),\n  plugins: [\n    {\n      test: /.*\\.(wxss)$/,\n      action: ({ data }) => {\n        // Example: simple CSS minification or just passing through\n        return data.replace(/\\s+/g, ' ').trim();\n      },\n    },\n  ],\n};\n\n// Create an instance of Entry with your configuration\n// For a production build, ensure isWatch is false.\nconst bundler = new Entry({ \n  config: minipackConfig \n});\n\n// Initialize and start the bundling process\nbundler.init().start()\n  .then(() => console.log('Mini-program build successful!'))\n  .catch(error => console.error('Mini-program build failed:', error));","lang":"typescript","description":"Demonstrates programmatic usage to initialize and run the bundler with a custom configuration, including a basic plugin for WXSS processing."},"warnings":[{"fix":"Always pin to exact versions (e.g., `\"weapp-minipack\": \"0.1.20\"`) and thoroughly review release notes before updating to avoid unexpected breakages.","message":"The package is currently in version `0.1.x`. This indicates an early stage of development where the API might not be stable, and breaking changes could occur in minor or even patch releases.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your configuration file path is correct when using the CLI (`weapp-minipack -c ./config.js`) or that the config object is correctly structured when using the programmatic API.","message":"Configuration for `weapp-minipack` is primarily done via a separate JavaScript file (e.g., `minipack.config.js`) or passed directly as an object to the `Entry` constructor. It does not integrate with `package.json` for configuration.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For ESM projects, use `import` statements as shown in the `imports` section. For CJS projects, stick to `require`. Ensure your `tsconfig.json` `module` and `moduleResolution` are set appropriately (e.g., `\"module\": \"NodeNext\", \"moduleResolution\": \"NodeNext\"`).","message":"While the library ships TypeScript types, its examples in the README predominantly use CommonJS `require` syntax. If integrating into a pure ESM project, you might encounter issues unless your build setup correctly handles CJS interop.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `weapp-minipack` is installed locally (`npm install weapp-minipack` or `yarn add weapp-minipack`) if using programmatic API, or globally (`npm install -g weapp-minipack`) for CLI. Verify `import` vs `require` usage matches your project type.","cause":"The package was not installed or installed incorrectly, or there's a CommonJS/ESM import mismatch.","error":"Error: Cannot find module 'weapp-minipack'"},{"fix":"Refactor your imports to use `import { Entry } from 'weapp-minipack';` and `import path from 'path';`. If you need to read JSON or CJS modules, consider dynamic `import()` or `createRequire`.","cause":"Attempting to use `require()` in an ECMAScript module context (.mjs file or `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Provide a `configPath` option like `{ configPath: path.resolve(__dirname, 'minipack.config.js') }` or pass the configuration object directly as `{ config: { /* your config here */ } }` to the `Entry` constructor.","cause":"When creating a new `Entry` instance, neither a `configPath` pointing to a config file nor a direct `config` object was provided.","error":"Error: configPath is required or config options must be provided directly."}],"ecosystem":"npm"}