twitter-bootstrap - 如何在reactjs应用程序中包含bootstrap css和js?

标签 twitter-bootstrap reactjs webpack

我是 ReactJS 新手,我想在我的 React 应用程序中包含 bootstrap

我已经通过npm install bootstrap --save安装了bootstrap

现在,想要在我的 React 应用程序中加载 Bootstrap CSS 和 JS。

我正在使用 webpack。

webpack.config.js

var config = {
    entry: './src/index',

    output: {
        path: './',
        filename: 'index.js'
    },

    devServer: {
        inline: true,
        port: 8080,
        historyApiFallback: true,
        contentBase:'./src'
    },

    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel',

                query: {
                    presets: ['es2015', 'react']
               }
            }
        ]
    }
};

module. exports = config;

我的问题是“如何从节点模块将 bootstrap CSS 和 JS 包含在 ReactJS 应用程序中?”如何设置 bootstrap 以包含在我的 React 应用程序中?

最佳答案

如果您是 React 新手并且使用 create-react-app cli 设置,请运行下面的 npm 命令以包含最新版本 Bootstrap 。

npm install --save bootstrap

npm install --save bootstrap@latest

然后将以下导入语句添加到 index.js 文件中。 (https://getbootstrap.com/docs/4.4/getting-started/webpack/#importing-compiled-css)

import '../node_modules/bootstrap/dist/css/bootstrap.min.css';

import 'bootstrap/dist/css/bootstrap.min.css';

不要忘记使用 className 作为目标元素的属性(react 使用 className 作为属性)。

关于twitter-bootstrap - 如何在reactjs应用程序中包含bootstrap css和js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40037657/

相关文章:

ruby-on-rails - 没有路由匹配 { :action= >"show", :controller= >"users"}

javascript - 带有 Bootstrap 布局的 jQuery UI Draggable

javascript - JSX 如何为带有复选框输入的元素插入 props?

webpack - 如何告诉 Webpack 不要打包配置文件

javascript - 如何解决使用 Webpack 构建的 `require` 别名,用于 React 单元测试?

html - 我怎样才能摆脱网站顶部和导航栏之间的开放空间( Bootstrap )

html - knockout 不喜欢另一个里面的html标签吗?

javascript - getDerivedStateFromError 和 componentDidCatch 之间有什么区别

javascript - React Gulpfile watchify 不更新

node.js - 升级到 Node v8 后,Webpack 无法编译 React 代码(在 Ubuntu 16 上)