參考:
redux
reach-router
rollup-starter-lib
rollup-starter-app
roller-cli
create-react-library
1、安裝
npm install --global rollup
2、命令:
rollup -c
默認指向rollup.config.js
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import image from 'rollup-plugin-image';
import sizes from 'rollup-plugin-sizes';
// import env from 'rollup-plugin-env';
// import uglify from 'rollup-plugin-uglify';
import pkg from './package.json';
const external = Object.keys(pkg.dependencies || {});
export default {
input: 'src/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
plugins: [
// env({ NODE_ENV: 'production' }),
peerDepsExternal(),
postcss({
modules: true,
}),
image(),
babel({
exclude: 'node_modules/**',
}),
resolve(),
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/react/index.js': ['Component', 'PureComponent', 'Children', 'createElement'],
},
}),
// uglify(),
sizes({ details: true }),
],
external, // dependencies 內 不須要打包進去,運行時加載
};
3、
rollyup 默認將相對路徑加載, 若是想加載node_module 須要用rollup-plugin-node-resolve.
Rollup will only resolve relative module IDs by default.
If you do want to include the module in your bundle, you need to tell Rollup how to find it. In most cases, this is a question of using rollup-plugin-node-resolve.
四
Since most packages in your node_modules folder are probably legacy CommonJS rather than JavaScript modules, you may need to use rollup-plugin-commonjs:
5、
rollup-plugin-babel
在Babel實際編譯代碼以前,須要進行配置。 建立一個新文件src/.babelrc: