All Projects → guless → Mpx Webpack Plugin

guless / Mpx Webpack Plugin

原生小程序开发定制 webpack 插件套装

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mpx Webpack Plugin

Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (+176.47%)
Mutual labels:  webpack-plugin, webpack-loader
Svg Sprite Loader
Webpack loader for creating SVG sprites.
Stars: ✭ 1,822 (+5258.82%)
Mutual labels:  webpack-plugin, webpack-loader
Svg Sprite Webpack Plugin
Webpack plugin for loading/extracting SVGs into a sprite file
Stars: ✭ 73 (+114.71%)
Mutual labels:  webpack-plugin, webpack-loader
React Webpack4 Cook
💯The most powerful webpack4 tutorial in the universe
Stars: ✭ 152 (+347.06%)
Mutual labels:  webpack-plugin, webpack-loader
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+429.41%)
Mutual labels:  webpack-plugin, webpack-loader
stylos
Webpack plugin to automatically generate and inject CSS utilities to your application
Stars: ✭ 60 (+76.47%)
Mutual labels:  webpack-plugin, webpack-loader
Webpack Tools
☕️Just a simple webpack sample project.
Stars: ✭ 106 (+211.76%)
Mutual labels:  webpack-plugin, webpack-loader
Webpack.js.org
Repository for webpack documentation and more!
Stars: ✭ 2,049 (+5926.47%)
Mutual labels:  webpack-plugin, webpack-loader
Workerize Loader
🏗️ Automatically move a module into a Web Worker (Webpack loader)
Stars: ✭ 2,135 (+6179.41%)
Mutual labels:  webpack-plugin, webpack-loader
webpack-demos
webpack小练习
Stars: ✭ 17 (-50%)
Mutual labels:  webpack-plugin, webpack-loader
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (+935.29%)
Mutual labels:  webpack-plugin, webpack-loader
Flow Bin Loader
webpack loader for Flow
Stars: ✭ 11 (-67.65%)
Mutual labels:  webpack-loader
Alaweb
一套 Vue 代码,多端可用(H5、小程序、苹果App、安卓App、头条等)。系统含150+页面,200+组件(5端通用),30+元件(每个终端独立完成)
Stars: ✭ 837 (+2361.76%)
Mutual labels:  wechat-app
Masterwechatapp
『微信小程序』优秀教程、轮子、开源项目 资源汇总
Stars: ✭ 826 (+2329.41%)
Mutual labels:  wechat-app
Node Config Loader
Scan directories and loads config json and yaml files
Stars: ✭ 5 (-85.29%)
Mutual labels:  webpack-loader
Thread Loader
Runs the following loaders in a worker pool
Stars: ✭ 945 (+2679.41%)
Mutual labels:  webpack-loader
Less Loader
Compiles Less to CSS
Stars: ✭ 851 (+2402.94%)
Mutual labels:  webpack-loader
Prerender Spa Plugin
Prerenders static HTML in a single-page application.
Stars: ✭ 7,018 (+20541.18%)
Mutual labels:  webpack-plugin
Error Overlay Webpack Plugin
Catch errors with style 💥✨
Stars: ✭ 821 (+2314.71%)
Mutual labels:  webpack-plugin
Karma Webpack
Karma webpack Middleware
Stars: ✭ 818 (+2305.88%)
Mutual labels:  webpack-plugin

原生小程序开发套装(Mini Program X)

⚠️注意:

  • 该插件仅支持 [email protected] 以上的版本。
  • 该插件仅为使用原生小程序平台提供功能做 webpack 编译支持,因此不提供 虚拟DOM(Visual DOM) 支持。如果你喜欢 VUE 的开发模式,建议使用 mpvue 等其他框架进行开发。

功能特点

  • 支持多个平台:微信小程序(wechat)、支付宝小程序(alipay)、百度小程序(baidu)。
  • 支持 webpack 所有的功能,包括但不限于插件(plugins)、加载器(loaders)、解析器(resolvers)等。
  • 支持通过 npm install 安装第三方的小程序模块(页面,组件等),也就是说我们可以开发通用的组件并发布到 npm 上提供给其他小程序使用。

相关资料

起步

npm i webpack webpack-cli --save-dev
npm i mpx-webpack-plugin --save-dev

配置 npm scripts

{
    "name": "awesome-miniprogram",
    "version": "1.0.0",
    ...
    "scripts": {
        "watch": "npm run build -- --wacth",             /*< 开发模式 >*/
        "build": "webpack --config=./webpack.config.js"  /*< 生产模式 >*/
    }
}

💡小技巧:通过 webpack --env.* 可以添加自定的命令行参数,例如:我们可以通过 webpack --env.target=<production|development> 来代替以前使用 cross-env NODE_ENV=<production|development> webpack 来区分开发环境和生产环境。参考文档:Environment Variables

配置 webpack.config.js

const MPXPlugin = require("mpx-webpack-plugin");
const path = require("path");

module.exports = {
    "context": __dirname,
    "entry": "./src/app", // 具体如何配置入口点,请参考下面的【小程序入口点(Entry-Points)】。
    "output": {
        "path": path.resolve(__dirname, "./dist"),
        "filename": "[name].js"
    },
    
    "plugins": [
        new MPXPlugin({ "platform": "wechat" })
    ]
};

通过 webpack.config.js 导出多份配置文件,可以一次性编译成多个平台的小程序。

const MPXPlugin = require("mpx-webpack-plugin");
const path = require("path");

module.exports = [
    {
        "context": __dirname,
        "entry": "./src/app", // 具体如何配置入口点,请参考下面的【小程序入口点(Entry-Points)】。
        "output": {
            "path": path.resolve(__dirname, "./dist/wechat/"),
            "filename": "[name].js"
        },
        
        "plugins": [
            new MPXPlugin({ "platform": "wechat" })
        ]
    },
    {
        "context": __dirname,
        "entry": "./src/app", // 具体如何配置入口点,请参考下面的【小程序入口点(Entry-Points)】。
        "output": {
            "path": path.resolve(__dirname, "./dist/baidu/"),
            "filename": "[name].js"
        },
        
        "plugins": [
            new MPXPlugin({ "platform": "baidu" })
        ]
    },
];

小程序入口点(Entry-Points)

定义小程序入口点可以通过以下 3 种配置方式:

使用对象语法(Object Syntax)指定小程序入口点时,建议使用 "app" 作为入口点的名称(entryChunkName)。

MPXPlugin( options )

Options

类型 名称 默认值 说明
{string} name "app" 指定小程序入口点的名称。如果使用对象语法(Object Syntax)配置 entry,则插件通过该字段查找小程序的入口点。
{string} platform "wechat" 指定运行的小程序平台,可选值:["wechat", "alipay", "baidu"]
  • "wechat":微信小程序。
  • "alipay":支付宝小程序。
  • "baidu":百度小程序。
{Array<string>} chunks undefined 当使用 splitChunks 分离公共模块后,通过 chunks 将公共模块插入到 app.js 之前。
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].