Lor*_*one 3 javascript npm bootstrap-5
我在使用 bootstrap5 和 NPM 时遇到一些问题。网站设计使用 bootstrap 并且可以工作,但不是所有的 js(下拉菜单、模态等...),我只是想学习如何在没有 CDN 的情况下导入 js bs 包。有人可以帮助我吗?谢谢你的时间
我的步骤:
npm install bootstrap@5.0.0-alpha1
npm install popper.js --save
npm intsall node-sass --save-d
Run Code Online (Sandbox Code Playgroud)
包.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"
}
}
Run Code Online (Sandbox Code Playgroud)
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'
]
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
src/js/app.js
import 'bootstrap';
Run Code Online (Sandbox Code Playgroud)
src/scss/app.scss
@import '../../node_modules/bootstrap/scss/bootstrap.scss';
Run Code Online (Sandbox Code Playgroud)
通过以下步骤解决:
import '@popperjs/core';之前import 'bootstrap';感谢贾巴的帮助。