How to use semantic-ui in react with webpack?

后端 未结 2 1599
感动是毒
感动是毒 2021-02-09 13:22

I would like to use CommonJS to include semantic-ui in my react jsx file. I installed semantic-ui with bower, and webpack is correctly configured to include the bower_components

相关标签:
2条回答
  • 2021-02-09 14:15

    try the provide-plugin like so:

      plugins: [
        new ProvidePlugin({
          'jQuery': 'jquery'
        })
      ],
    
    0 讨论(0)
  • 2021-02-09 14:25

    As for the CSS you're going to want to load that in your index/whatever.html file before sourcing your JS.

    Try the following before you require semantic-ui:

    var $ = jQuery = require('jquery/dist/jquery.js');
    window.jQuery = $; // Assure it's available globally.
    var s = require('semantic-ui/dist/semantic-ui.js');
    

    Not 100% sure this will work but it's worth a try.

    Things can get tricky with CommonJS modules. Also, might be worth looking into React+Browserify. Makes it super simple to import NPM modules using require.

    0 讨论(0)
提交回复
热议问题