Webpack 整合Bootstrap

本文最后更新于:2022年1月11日 晚上

Webpack 整合Bootstrap

安装

1
$ yarn add jquery popper.js bootstrap

配置

  • index.js
1
2
import 'bootstrap'
import "./styles/index.scss"
  • index.scss
1
2
@import "style";
@import "~bootstrap/scss/bootstrap";
  • webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const webpack = require('webpack')

module.exports = {
module: {
rules: [
{
test: /\.(scss)$/,
use: [{
loader: 'style-loader', // inject CSS to page
}, {
loader: 'css-loader', // translates CSS into CommonJS modules
}, {
loader: 'postcss-loader', // Run post css actions
options: {
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
require('autoprefixer')
];
}
}
}, {
loader: 'sass-loader' // compiles SASS to CSS
}]
},
],
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
},
};

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!