Skip to content

Instantly share code, notes, and snippets.

@xuxucode
Last active November 11, 2024 16:56

Revisions

  1. xuxucode revised this gist Aug 24, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions import-corejs-missing-modules.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@
    参考文档:https://github.com/zloirock/core-js/tree/master/packages/core-js-builder

    ```js
    import builder from 'core-js-builder'

    await builder({
    // 所有需要的模块('core-js/actual/url' 包含 URL 和 URLSearchParams:https://github.com/zloirock/core-js#url-and-urlsearchparams)
    modules: ['core-js/actual/url'],
  2. xuxucode renamed this gist Aug 21, 2023. 1 changed file with 0 additions and 0 deletions.
  3. xuxucode revised this gist Aug 21, 2023. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions import-missing-modules.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@
    微信小程序已经内置了部分 `core-js` polyfill,但不全面。参考:
    - https://github.com/wechat-miniprogram/miniprogram-compat/blob/master/data/polyfill.json
    - https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/js-support.html#%E6%A0%87%E5%87%86-ECMAScript-%E6%94%AF%E6%8C%81

    可以通过手动打包缺失的模块,并导入项目。
    需要手动打包缺失的模块,并导入项目。

    ### 第一步: 以打包 `URL``URLSearchParams` 为例,运行此脚本,最后生成文件 `corejs-url.js` (139 KB)
    参考文档:https://github.com/zloirock/core-js/tree/master/packages/core-js-builder
  4. xuxucode revised this gist Aug 21, 2023. 1 changed file with 0 additions and 21 deletions.
    21 changes: 0 additions & 21 deletions corejs-url.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    /**
    * core-js 3.32.1
    * © 2014-2023 Denis Pushkarev (zloirock.ru)
    * license: https://github.com/zloirock/core-js/blob/v3.32.1/LICENSE
    * source: https://github.com/zloirock/core-js
    *//*
    * size: 139.40KB w/o comments
    *//*
    * modules:
    * web.url
    * web.url.can-parse
    * web.url.to-json
    * web.url-search-params
    * web.url-search-params.delete
    * web.url-search-params.has
    * web.url-search-params.size
    */
    !function (undefined) { 'use strict'; /******/ (function(modules) { // webpackBootstrap
    // ... 省略

    }
  5. xuxucode revised this gist Aug 21, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions corejs-url.js
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,5 @@
    */
    !function (undefined) { 'use strict'; /******/ (function(modules) { // webpackBootstrap
    // ... 省略

    }
  6. xuxucode revised this gist Aug 21, 2023. No changes.
  7. xuxucode revised this gist Aug 21, 2023. No changes.
  8. xuxucode revised this gist Aug 21, 2023. 2 changed files with 43 additions and 37 deletions.
    37 changes: 0 additions & 37 deletions builder-script.js
    Original file line number Diff line number Diff line change
    @@ -1,37 +0,0 @@
    // 参考文档:https://github.com/zloirock/core-js/tree/master/packages/core-js-builder

    // 第一步: 以打包 `URL` 和 `URLSearchParams` 为例

    // 运行此脚本,最后生成文件 `corejs-url.js`
    await builder({
    // 所有需要的模块('core-js/actual/url' 包含 URL 和 URLSearchParams:https://github.com/zloirock/core-js#url-and-urlsearchparams)
    modules: ['core-js/actual/url'],
    summary: {
    console: { size: true, modules: true },
    comment: { size: true, modules: true },
    },
    format: 'bundle',
    // 打包后的目标文件名
    filename: './corejs-url.js',
    })

    // 第二步:把 `corejs-url.js` 复制到小程序项目里,比如:

    ```tree
    ├── app.json
    ├── app.ts
    ├── lib
    │   └── corejs-url.js
    ├── pages
    └── utils
    └── util.ts
    ```

    // 第三步:导入 `corejs-url.js`:
    ```
    // 在 app.ts 文件
    import './lib/corejs-url.js'
    ```

    // 备注
    // 小程序开发工具(我的版本是 1.06.2307260 darwin)已经实现 `globalThis.URL` 和 `globalThis.SearchParams`,`corejs-url`仅在真机上有效。
    43 changes: 43 additions & 0 deletions import-missing-modules.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    微信小程序已经内置了部分 `core-js` polyfill,但不全面。参考:
    - https://github.com/wechat-miniprogram/miniprogram-compat/blob/master/data/polyfill.json
    - https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/js-support.html#%E6%A0%87%E5%87%86-ECMAScript-%E6%94%AF%E6%8C%81

    可以通过手动打包缺失的模块,并导入项目。

    ### 第一步: 以打包 `URL``URLSearchParams` 为例,运行此脚本,最后生成文件 `corejs-url.js` (139 KB)
    参考文档:https://github.com/zloirock/core-js/tree/master/packages/core-js-builder

    ```js
    await builder({
    // 所有需要的模块('core-js/actual/url' 包含 URL 和 URLSearchParams:https://github.com/zloirock/core-js#url-and-urlsearchparams)
    modules: ['core-js/actual/url'],
    summary: {
    console: { size: true, modules: true },
    comment: { size: true, modules: true },
    },
    format: 'bundle',
    // 打包后的目标文件名
    filename: './corejs-url.js',
    })
    ```

    ### 第二步:把 `corejs-url.js` 复制到小程序项目里,比如:

    ```tree
    ├── app.json
    ├── app.ts
    ├── lib
    │   └── corejs-url.js
    ├── pages
    └── utils
    └── util.ts
    ```

    ### 第三步:导入 `corejs-url.js`
    ```
    // 在 app.ts 文件
    import './lib/corejs-url.js'
    ```

    ### 备注
    - 小程序开发工具(我的版本是 1.06.2307260 darwin)已经实现 `globalThis.URL``globalThis.SearchParams``corejs-url`**仅在真机上有效**
  9. xuxucode created this gist Aug 21, 2023.
    37 changes: 37 additions & 0 deletions builder-script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    // 参考文档:https://github.com/zloirock/core-js/tree/master/packages/core-js-builder

    // 第一步: 以打包 `URL` 和 `URLSearchParams` 为例

    // 运行此脚本,最后生成文件 `corejs-url.js`
    await builder({
    // 所有需要的模块('core-js/actual/url' 包含 URL 和 URLSearchParams:https://github.com/zloirock/core-js#url-and-urlsearchparams)
    modules: ['core-js/actual/url'],
    summary: {
    console: { size: true, modules: true },
    comment: { size: true, modules: true },
    },
    format: 'bundle',
    // 打包后的目标文件名
    filename: './corejs-url.js',
    })

    // 第二步:把 `corejs-url.js` 复制到小程序项目里,比如:

    ```tree
    ├── app.json
    ├── app.ts
    ├── lib
    │   └── corejs-url.js
    ├── pages
    └── utils
    └── util.ts
    ```

    // 第三步:导入 `corejs-url.js`:
    ```
    // 在 app.ts 文件
    import './lib/corejs-url.js'
    ```

    // 备注
    // 小程序开发工具(我的版本是 1.06.2307260 darwin)已经实现 `globalThis.URL` 和 `globalThis.SearchParams`,`corejs-url`仅在真机上有效。
    20 changes: 20 additions & 0 deletions corejs-url.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /**
    * core-js 3.32.1
    * © 2014-2023 Denis Pushkarev (zloirock.ru)
    * license: https://github.com/zloirock/core-js/blob/v3.32.1/LICENSE
    * source: https://github.com/zloirock/core-js
    *//*
    * size: 139.40KB w/o comments
    *//*
    * modules:
    * web.url
    * web.url.can-parse
    * web.url.to-json
    * web.url-search-params
    * web.url-search-params.delete
    * web.url-search-params.has
    * web.url-search-params.size
    */
    !function (undefined) { 'use strict'; /******/ (function(modules) { // webpackBootstrap
    // ... 省略
    }