gpt4 book ai didi

javascript - 如何在与 Webpack 捆绑在一起的 Angular 1 应用程序中使用 Bootstrap

转载 作者:行者123 更新时间:2023-12-03 04:49:28 24 4
gpt4 key购买 nike

我正在尝试在依赖于捆绑的 JS 和 CSS 的 Angular 1 应用程序中使用 Bootstrap。这是我当前的 webpack.config.js:

var webpack = require('webpack');

module.exports = {
context: __dirname + '/src/assets/app',
entry: {
app: './app.module.js',
vendor: [
'angular',
'jquery',
'bootstrap/dist/css/bootstrap.css',
'bootstrap'
]
},
output: {
path: __dirname + '/src/assets/jsBundles',
filename: 'app.bundle.js'
},
target: 'web',
node: {
fs: 'empty'
},
devtool: 'eval',
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.bundle.js'
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
],
module: {
rules: [
{
test: /\.html$/,
use: ['html-loader']
}, {
test: /\.css$/,
use: ['css-loader']
}, {
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
use: ['url-loader']
}
]
}
};

我的 Angular 应用程序已成功加载,但当我尝试使用任何 Bootstrap 组件或 CSS 时,它们不起作用。不会出现错误,但不会应用 Bootstrap 样式,并且像下拉菜单或模态功能这样的 Bootstrap JS 无法工作。当我查看 vendor.bundle.js 时,我看到了所有 Bootstrap JS、CSS 和字体。我需要在客户端做一些事情来“加载”Bootstrap吗?

最佳答案

尝试在ProvidePlugin中定义"window.jQuery": "jquery"

作为引用,您可以引用 webpack.config.js & webpack.common.config.js在链接中或可以引用入门套件 Angular 1.x and Webpack

关于javascript - 如何在与 Webpack 捆绑在一起的 Angular 1 应用程序中使用 Bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42722049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com