Having some issues with implementing Bootstrap5 and NPM. The website design is using bootstrap, which works fine, but not all the JavaScript components (dropdowns, modals, etc). I want to figure out how to import the Bootstrap JS bundle without relying on CDNs. Can anyone provide guidance? Thank you for your help.
My steps:
npm install [email protected]
npm install popper.js --save
npm install node-sass --save
Package.json:
{
"name": "xlf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "./node_modules/.bin/webpack --watch",
"sass": "node-sass --watch src/scss -o dist/css --output-style nested"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^5.0.0-alpha1",
"popper.js": "^1.16.1"
},
"devDependencies": {
"node-sass": "^5.0.0",
"webpack": "^5.26.0",
"webpack-cli": "^4.5.0"
}
}
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist','js'),
filename: 'app.js',
},
mode: 'production',
module: {
rules:[
{
test: /.(scss|css)$/,
use:
[
{
options: { reloadAll: true },
},
'css-loader',
'sass-loader',
'node-sass'
]
}
]
}
};
src/js/app.js
import 'bootstrap';
src/scss/app.scss
@import '../../node_modules/bootstrap/scss/bootstrap.scss';