snippetreactCritical
How to include bootstrap css and js in reactjs app?
Viewed 0 times
bootstrapincludeandappreactjscsshow
Problem
I am new to ReactJS, I want to include bootstrap in my React app
I have installed bootstrap by
Now, want to load bootstrap CSS and JS in my React app.
I am using webpack.
webpack.config.js
My issue is “how to include bootstrap CSS and JS in ReactJS app from node modules?" How to set up for bootstrap to include in my React app?
I have installed bootstrap by
npm install bootstrap --saveNow, want to load bootstrap CSS and JS in my React app.
I am using 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;My issue is “how to include bootstrap CSS and JS in ReactJS app from node modules?" How to set up for bootstrap to include in my React app?
Solution
If you are new to React and using
or
Then add the following import statement to
or
don't forget to use
create-react-app cli setup, run the npm command below to include the latest version of bootstrap.npm install --save bootstrapor
npm install --save bootstrap@latestThen add the following import statement to
index.js file. (https://getbootstrap.com/docs/4.4/getting-started/webpack/#importing-compiled-css)import '../node_modules/bootstrap/dist/css/bootstrap.min.css';or
import 'bootstrap/dist/css/bootstrap.min.css';don't forget to use
className as attribute on target elements (react uses className as attribute instead of class).Code Snippets
npm install --save bootstrapnpm install --save bootstrap@latestimport '../node_modules/bootstrap/dist/css/bootstrap.min.css';import 'bootstrap/dist/css/bootstrap.min.css';Context
Stack Overflow Q#40037657, score: 354
Revisions (0)
No revisions yet.