Giter Club home page Giter Club logo

minioptimizer's Introduction

Optimizer

小程序包大小优化工具

基本能力

移动(拷贝)子包依赖到子包目录中

对于多子包依赖的相同文件,一般会放在主包中,导致主包会包含并不依赖的文件,包体积变大

如何使用

npm install mini-optimizer -D

命令行

Usage: optimize <path> [options]

Options:
  -t, --type <type>                     type of mini app wx or my (default: "wx")
  -c, --config <path>                   path to config file (default: "./optimizer.config.json")
  -o, --output <path to fold>           redirect output to the fold
  --remove-useless-file                 remove useless file
  --minify-css                          minify css
  --minify-js                           minify js
  --minify-xs                           minify xs (.sjs|.wxs)
  --minify-xml                          minify xml
  --minify-json                         minify json
  --rename-file                         rename file
  --renamed-files-map <file path>       write renamed file map to the file (default: "./renamed-files-map.json")
  --rename-component                    rename component
  --renamed-components-map <file path>  write renamed component map to the file (default: "./renamed-components-map.json")
  -h, --help                            display help for command

配置

{
  "renameFile": true,
  "renameComponent": true,
  "minifyJs": true,
  "minifyCss": true,
  "minifyXs": true,
  "minifyXml": true,
  "minifyJson": true,
  "removeUselessFile": true,
  "uselessExculde": [
    "assets/**/*.*"
  ],
  "renameExculde": [
    "assets/images/dish-default.png"
  ],
  "plugins": ["mini-optimizer/lib/plugins/merge-import"],
  "output": "./source-d"
}

renameFile

重命名文件,即:把目录结构打平并且缩短文件名的长度

文件路径会被包含在JS中,引用的文件路径越长包体积越大

renameComponent

重命名组件, 即:把组件名称替换为更短的名称

为了XML语义化,在开发时会使用语义化的标签名,比如user-info, 这样会增加xml的大小,使用更短的组件名降低包体积。

minifyJs

压缩JS体积

minifyXs

压缩.wxs.sjs体积

minifyCss

压缩CSS体积

minifyXml

压缩XML体积

minifyJSON

压缩JSON体积

removeUselessFile

移除无用文件

uselessExculde

保留的文件 支持glob

renameExculde

不重命名的文件 支持glob

output

输出的文件夹

插件

merge-import

JS文件依赖越多包体积越大,所有通过合并import可以有效减小包体积

- import Event from '../../common/base/event';
- import System from '../../common/utils/system';
- import { getId } from '../../lib/bizdata';
+ import { b_ as Event, c5 as System, R as getId } from "./__entry__";

minioptimizer's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

minioptimizer's Issues

微信小程序打包优化后,分包无法加载到组件

使用小程序压缩优化后,发现分包的组件找不到,报错:
VM28 WAService.js:2 Component is not found in path "pages/member/_/components/basic-component/BaseButton/index" (using by "pages/member/info/index")(env: macOS,mp,1.05.2204250; lib: 2.24.6)
1657619728892

打包没有使用其他选项,都是默认配置,打包指令
node "/Users/apple/Downloads/MiniOptimizer-master/lib/bin.js" /Users/apple/Desktop/app/business-district-applet/dist/build/mp-weixin --type wx -o /Users/apple/Desktop/app/business-district-applet/dist/build/mp-weixin2

Error: unknown file: ReferenceError: Used resJson: const binding before declaration

BABEL] Note: The code generator has deoptimised the styling of undefined as it exceeds the max of 500KB.
/Users/shileicao/code/happy-drinking-user/node_modules/babel-helper-evaluate-path/lib/index.js:233
throw new Error(ReferenceError: Used ${refPath.node.name}: + ${binding.kind} binding before declaration);
^

Error: unknown file: ReferenceError: Used resJson: const binding before declaration
at evaluateBasedOnControlFlow (/Users/shileicao/code/happy-drinking-user/node_modules/babel-helper-evaluate-path/lib/index.js:233:15)

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.