Giter VIP home page Giter VIP logo

mpx-webpack-plugin's Introduction

原生小程序开发套装(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 之前。

mpx-webpack-plugin's People

Contributors

samlv9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mpx-webpack-plugin's Issues

百度小程序图片路径问题

examples 中的例子,app.json 中的图片路径 build 后没办法识别,路径如下:
"iconPath": "/images\ticket_4bf11d.png",,将 \ 改成 / 就好了,能否修正下。

Cannot read property 'properties' of undefined 小程序组件打包,不支持?

e:\其他\mpx-webpack-plugin-master>npm run build

[email protected] build e:\其他\mpx-webpack-plugin-master
webpack --config=./examples/webpack.config.js

e:\其他\mpx-webpack-plugin-master\node_modules_webpack-cli@2.1.5@webpack-cli\bin\config-yargs.js:89
describe: optionsSchema.definitions.output.properties.path.description,
^

TypeError: Cannot read property 'properties' of undefined
at module.exports (e:\其他\mpx-webpack-plugin-master\node_modules_webpack-cli@2.1.5@webpack-cli\bin\config-yargs.js:89:48)
at e:\其他\mpx-webpack-plugin-master\node_modules_webpack-cli@2.1.5@webpack-cli\bin\webpack.js:60:27
at Object. (e:\其他\mpx-webpack-plugin-master\node_modules_webpack-cli@2.1.5@webpack-cli\bin\webpack.js:515:3)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: webpack --config=./examples/webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache_logs\2019-02-27T10_36_45_386Z-debug.log

image

qq microApp compiling err

I'll try to use English to discribe this question..
I use the mpx to reduce a qq microApp which code based on wx syntax, and I use < editor > component, the question is: [template compiler] "resourceURL": < editor > is not supported in qq environment!
But actually, editor is working in qq , how can I resolve this question pls?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.