How to use a library from a CDN in a Webpack project in production

前端 未结 3 2047
太阳男子
太阳男子 2020-11-30 02:16

I\'d like to use react.min.js from a CDN in production (e.g. https://unpkg.com/react@15.3.1/dist/react.min.js)

What is the best way to get Webpack to tr

3条回答
  •  臣服心动
    2020-11-30 03:08

    In your webpack config you can use the externals option which will import the module from the environment instead of trying to resolve it normally:

    // webpack.config.js
    module.exports = {
      externals: {
        'react': 'React'
      }
      ...
    };
    

    Read more here: https://webpack.js.org/configuration/externals/

提交回复
热议问题