I want to built a react library into a CDN instead of uploading to npm?
The library I wrote depends on some other libs (eg axios, react ...) I'm using rollup to build umd, but then I try to install it in a project in the html script, when I import it, it says the axios library is not installed.
If anyone has ever built a library on CDN, please tell me, thank you very much. Here is my config:
import typescript from 'rollup-plugin-typescript2';
import css from 'rollup-plugin-css-only';
import pkg from './package.json';
import externalGlobals from 'rollup-plugin-external-globals';
import { visualizer } from 'rollup-plugin-visualizer';
import { terser } from 'rollup-plugin-terser';
// import obfuscator from 'rollup-plugin-obfuscator';
export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
name: 'lib',
},
{
file: pkg.module,
format: 'esm',
exports: 'named',
name: 'lib',
},
{
file: pkg.iife,
format: 'iife',
exports: 'named',
name: 'lib',
},
{
file: pkg.browser,
format: 'umd',
exports: 'named',
name: 'lib',
},
],
external: [...Object.keys(pkg.dependencies || {})],
plugins: [
terser(),
typescript({
typescript: require('typescript'),
}),
css({ output: 'bundle.css' }),
externalGlobals({
react: 'React',
'react-dom': 'ReactDOM',
}),
visualizer()
],
};
thank you!