-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack 3 + Bootstrap 4 beta example project #24370
Comments
@Johann-S: thoughts? IMO it's not our job to teach how to use each tool. |
@XhmikosR See it this way: Bootstrap 3 needs JQuery for JavaScript components and SASS/LESS compiler for
Bootstrap 4 needs JQuery and Popper.js for JavaScript components and SASS/LESS compiler for
For webpack complete # dependencies to install through npm
npm install --save [email protected] jquery popper.js
npm install --save-dev autoprefixer babel-core babel-loader babel-preset-es2015 css-loader extract-text-webpack-plugin node-sass postcss-loader precss sass-loader style-loader webpack // webpack.config.js
const webpack = require('webpack')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const path = require('path')
const extractSass = new ExtractTextPlugin({
filename: "styles.css",
});
module.exports = {
entry: './src/index.js',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'public')
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
use: [{
loader: 'babel-loader',
options: {
presets: [
['es2015', { modules: false }]
]
}
}]
},
{
test: /\.(scss)$/,
use: extractSass.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use: [{
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
})
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery", // Used for Bootstrap JavaScript components
jQuery: "jquery", // Used for Bootstrap JavaScript components
Popper: ['popper.js', 'default'] // Used for Bootstrap dropdown, popup and tooltip JavaScript components
}),
extractSass
]
}; // ./src/index.js
// Bootstrap dependencies
window.$ = window.jQuery = require('jquery') // required for bootstrap
window.Popper = require('popper.js') // required for tooltip, popup...
require('bootstrap')
import './index.scss' // include bootstrap css file with own modifications
// tooltip and popover require javascript side modification to enable them (new in Bootstrap 4)
// use tooltip and popover components everywhere
$(function (){
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
})
// Your code here.... /* ./src/_custom.scss
$body-bg: $gray-900;
$body-color: $gray-600; /* ./src/index.scss */
@import "~bootstrap/scss/bootstrap";
@import "custom"; <!-- ./public/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="container">
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
</div>
<script src="app.js"></script>
</body>
</html> Indeed it is not your job to teach each tool, but that was not what was asked. What is asked is how to get started without need to dig issues and source code and that is your job, right? |
I am using create-react-app, and don't have access to webpack config. I am including partial bootstrap components this way. yarn add exports-loader index.js// jQuerySlim takes almost 25% of entire bundle :(
window.$ = window.jQuery = require('jquery/dist/jquery.slim');
window.Popper = require('popper.js');
window.Util = require('exports-loader?Util!bootstrap/js/dist/util'); // eslint-disable-line
window.Dropdown = require('exports-loader?Dropdown!bootstrap/js/dist/dropdown'); // eslint-disable-line
window.Modal = require('exports-loader?Modal!bootstrap/js/dist/modal'); // eslint-disable-line First I tried to include them from And for index.scss// BASE
@import "font-faces";
@import "bootstrap";
@import "../icons/style.css";
// BOOTSTRAP OVERRIDES
@import "resets";
@import "icons";
@import "helpers";
@import "layout";
...
// COMPONENTS
@import "components";
// CONTAINERS
@import "header";
@import "topcontent";
.. _bootstrap.scssKnow I could import @import "../../node_modules/bootstrap/scss/functions";
@import "variables";
@import "added-vars";
@import "../../node_modules/bootstrap/scss/variables";
@import "../../node_modules/bootstrap/scss/mixins";
//@import "../../node_modules/bootstrap/scss/print";
@import "../../node_modules/bootstrap/scss/reboot";
@import "../../node_modules/bootstrap/scss/type";
//@import "../../node_modules/bootstrap/scss/images";
@import "../../node_modules/bootstrap/scss/code";
@import "../../node_modules/bootstrap/scss/grid";
//@import "../../node_modules/bootstrap/scss/tables";
... |
Personnaly I would prefer an update of our documentation : https://getbootstrap.com/docs/4.0/getting-started/webpack/ |
@Johann-S I'll fork and modify it => |
If we need to update our docs, let's see issues and PRs for that rather than requesting an entire project for it. I'd be happy to see our docs refer to someone else's project, too. But otherwise, we won't be taking this on ourselves—we don't use webpack for maintain Bootstrap. |
Any suggestion about this error?
|
@niceKamrul try to install |
The problem was, "Babel loader has been disabled for files coming from node_modules" as descussed here. |
For others who come across this as I did while trying to set up Bootstrap 4 with Webpack, the method of requiring JQuery and Popper.js in the index.js file as described by @iamandrewluca significantly increases the bundle size if you are using all or most of the js plugins and css - in my own case it added about 160kb to the bundle size. |
Hi,
Webpack documentation was not enough to help me get started. It would be great to add complete minimum project examples to get started. Here is Webpack 3 + Bootstrap 4 beta project as example to show what I mean: https://github.com/xdvarpunen/webpackboot
The text was updated successfully, but these errors were encountered: