What should I do if I want to extract a react component that is referenced in multiple projects and put it on cdn?

the internship company has a component that needs to be used for several projects, which is particularly troublesome to modify each time. Now, if you want to extract this react component and put it on cdn, how do you do it?
can I just package it in webpack and take out the packaged file?
but the company"s code is all packaged together, so how to package it separately

Apr.03,2021

  1. package and publish to npm
  2. if you are sensitive, you can set up a private cnpm: within the company https://blog.csdn.net/kaosini..
  3. deployed to the company's private warehouse, npm can directly choose to rely on the warehouse project: https://docs.npmjs.com/cli/in.
  4. compiled into dll

all you have to solve is the problem of component sharing. Cdn seems to be making a mountain out of a molehill.

if the project shares a directory, set the component directory at the top of the directory;

if the project is connected to the same intranet, you can set the internal npm;

finally, you can consider publishing this component to npm for open source

=


// cdn.js
// need compile
class Button extends React.Component {
  render() {
    return (
      <div>
      </div>
    )
  }
}
window.customComponent = window.customComponent || {}
window.customComponent.Button = Button


// other app
const Button =  window.customComponent.Button

class Modal extends React.Component {
  render() {
    return (
      <div>
        <Button2 />
      </div>
    )
  }
}
Menu