实用程序包utils - 基于Rollup打包输出各模块文件(二) (2)

实用程序包utils - 基于Rollup打包输出各模块文件(二)

打包出来的文件怎么使用 AMD <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1.0"> <title>ataola utils</title> </head> <body> </body> <script src="http://cdn.bootcdn.net/ajax/libs/require.js/2.3.6/require.js"></script> <script> requirejs(["https://unpkg.com/@ataola/utils@0.1.10/dist/ataola-utils.amd.js"], function(ataola) { console.log(ataola) console.log(ataola.getVersion()) }); </script> </html>

https://zhengjiangtao.cn/show/zj/ataola-utils-amd.html

UMD <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1.0"> <title>ataola utils</title> </head> <body> </body> <script src="http://unpkg.com/@ataola/utils@0.1.10/dist/ataola-utils.umd.js"></script> <script> const ataola = this['ataola-utils']; console.log(ataola); console.log(ataola.getVersion()); </script> </html>

https://zhengjiangtao.cn/show/zj/ataola-utils-umd.html

IIFE <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1.0"> <title>ataola utils</title> </head> <body> </body> <script src="http://unpkg.com/@ataola/utils@0.1.10/dist/ataola-utils.min.js"></script> <script> // https://unpkg.com/@ataola/utils@0.1.10/dist/ataola-utils.js // https://cdn.jsdelivr.net/npm/@ataola/utils@0.1.10/dist/ataola-utils.js // use this['ataola-utils'] || window['ataola-utils'] const ataola = this['ataola-utils']; console.log(ataola); console.log(ataola.getVersion()); </script> </html>

https://zhengjiangtao.cn/show/zj/ataola-utils.html

ES Module <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content="width=device-width, initial-scale=1.0"> <title>utils unpkg</title> </head> <body> </body> <script type="module"> import * as ataola from 'https://unpkg.com/@ataola/utils@0.1.10/dist/ataola-utils.esm.js'; console.log(ataola); </script> </html>

https://zhengjiangtao.cn/show/zj/ataola-utils-amd.html

ComonJS

实用程序包utils - 基于Rollup打包输出各模块文件(二)

这里AMD相关的引入需要你先引入require.js的支持,如果是commonJS模块的话,需要用seajs,我试了下不是很好使,我放弃了别打我,建议直接在node.js环境下引入,如楼上

参考文献

Rollup官方文档:https://rollupjs.org/guide/zh/

Rollup插件库: https://github.com/rollup/plugins

IIFE: https://developer.mozilla.org/zh-CN/docs/Glossary/IIFE

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zydzzj.html