rollup开发自己的组件库(1)

开发的时候有这种需求,我们需要自己做自己公司的js/ui组件库,这时我们用rollup来进行组件库的开发
至于放在那里 可以放到npm官方 也可以安装自己的npm仓库

demo https://github.com/757566833/rollup-guide

1.关于 babel,typescript,webpack,rollup,前两者是转义工具,单纯的翻译功能,后两者是打包工具
2.之所以react采用rollup而并非webpack,大体上有这么几个文章在说明
https://github.com/nolanlawson/cost-of-small-modules/pull/8
https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c
https://github.com/facebook/react/pull/9327
https://github.com/facebook/react/issues/6351
https://github.com/facebook/react/pull/4230
https://github.com/facebook/react/issues/4927
https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/

3.安装rollup

yarn add  rollup  --dev

4.新建rollup.config.js

module.exports = {
    input: 'src/main.js',
    output: {
        file: 'dist/bundle.js',
        format: 'cjs'
    }
};

5.新建src/main.js

console.log('hello rollup')

6.更改package.json

...
"scripts": {
    "build":"rollup -c"
  }

7.打包

npm run build
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。