codecamp

MorJS 构建处理

MorJS 支持配置文件指定,因此在组件输出的时候,我们可以利用 MorJS 的 compile 能力来直接输出支持多端的构建产物。 这里以组件输出lib目录为示例。

项目根目录下新增 mor.build.config.ts 文件,用于组件编译输出

import { defineConfig } from '@morjs/cli'

export default defineConfig([
  {
    name: 'alipay',
    sourceType: 'alipay',
    target: 'alipay',
    compileMode: 'default',
    srcPath: './component',
    outputPath: './alipay'
  },
  {
    name: 'wechat',
    sourceType: 'alipay',
    target: 'wechat',
    compileMode: 'default',
    srcPath: './component',
    outputPath: './miniprogram_dist'
  }
])

pacakge.json 内容示例:

  • 增加相关 ​scripts
{
  "miniprogram": "miniprogram_dist",
  "alipay": "alipay",
  "files": [
    "miniprogram_dist",
    "alipay"
  ],
  "scripts": {
    "clean": "rm -rf alipay miniprogram_dist", // 清空构建产物目录
    "build": "npm run clean && mor compile --production --config mor.build.config.ts", // 构建产物
    "prepublishOnly": "npm run build", // 发布前进行一次构建,确保发布的代码是最新版本
    "compile": "mor compile", // 用于本地预览
    "dev": "mor compile --watch" // 用于本地预览
  }
}

后续通过 npm publish 发布即可


MorJS 小程序目录规范完善项目
MorJS 多端运行时基础库规范 概要
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

MorJS 指南

MorJS 基础用法

MorJS 配置

MorJS 编译相关配置

MorJS 进阶用法

MorJS Web开发

MorJS Web开发介绍

MorJS Web开发快速上手

MorJS Tabbar IOS 小黑条适配开关

MorJS 社区

MorJS 规范

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }