MorJS 構(gòu)建處理

2024-01-25 11:51 更新
MorJS 支持配置文件指定,因此在組件輸出的時(shí)候,我們可以利用 MorJS 的 compile 能力來直接輸出支持多端的構(gòu)建產(chǎn)物。 這里以組件輸出lib目錄為示例。

項(xiàng)目根目錄下新增 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 內(nèi)容示例:

  • 增加相關(guān) ?scripts?
{
  "miniprogram": "miniprogram_dist",
  "alipay": "alipay",
  "files": [
    "miniprogram_dist",
    "alipay"
  ],
  "scripts": {
    "clean": "rm -rf alipay miniprogram_dist", // 清空構(gòu)建產(chǎn)物目錄
    "build": "npm run clean && mor compile --production --config mor.build.config.ts", // 構(gòu)建產(chǎn)物
    "prepublishOnly": "npm run build", // 發(fā)布前進(jìn)行一次構(gòu)建,確保發(fā)布的代碼是最新版本
    "compile": "mor compile", // 用于本地預(yù)覽
    "dev": "mor compile --watch" // 用于本地預(yù)覽
  }
}

后續(xù)通過 npm publish 發(fā)布即可


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號