Exclude react from webpack bundle

后端 未结 3 1284
终归单人心
终归单人心 2020-12-14 06:33

I\'m trying to exclude react from my bundle which is generated by webpack. Reason being, we have a global version of react available on the page so I\'ll be using that.

3条回答
  •  庸人自扰
    2020-12-14 07:09

    webpack config:

    externals: {
        'react': 'React',
        'react-dom': 'ReactDOM',
        'react-router': 'ReactRouter'
    }
    

    add these to the bottom of index.html body.

    
    
    
    

    and, in your entry file, maybe index.js:

    var React = require('react');
    var ReactDOM = require('react-dom');
    var ReactRouter = require('react-router');
    
    const App = () => {
        return 
    webpack externals
    }; ReactDOM.render( , document.getElementById('container') );

提交回复
热议问题