Skip to content
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

add webpack to documentation #22423

Merged
merged 4 commits into from
May 26, 2017
Merged

add webpack to documentation #22423

merged 4 commits into from
May 26, 2017

Conversation

IdanCo
Copy link
Contributor

@IdanCo IdanCo commented Apr 12, 2017

Summary

Add a guide to the official docs on how to integrate Bootstrap with Webpack.

Motivation

Background

During the past few months i've been integrating bootstrap into several new and existing projects using webpack version 2. This led me to conduct a thorough research and tests on the best practices to achieve this integration. The results of these efforts are in this guide.

Technical

Check out a sample project which implements the steps detailed in this guide -
https://github.com/IdanCo/webpack-modular/tree/bootstrap4

Copy link
Member

@mdo mdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, the only question I have is around the placement of this on a separate page—need to think about that a bit more. Also, is there anyone else out there using Webpack that would like to chime in with a review here?

Copy link

@ajacksified ajacksified left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few minor optional comments, but otherwise this very similar to my own webpack config.

{% callout info %}
#### Customization

To implement the powerful [options](/getting-started/options/) Bootstrap offers, create `_custom.scss` and import it **before** Bootstrap.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you include examples elsewhere, may be nice to do the same here for clarity:

To implement the powerful [options](/getting-started/options/) Bootstrap offers, create a file for variables, such as `_custom.scss`, and import it **before** Bootstrap:

{% highlight scss %}
// theme.scss
$brand-primary: $green;
{% endhighlight %}

{% highlight scss %}
@import "theme.scss";
@import "~bootstrap/scss/bootstrap";
{% endhighlight %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajacksified thanks for the feedback! i'll push a new PR later

group: getting-started
---

Use [webpack](https://webpack.js.org/) to bundle Bootstrap into your project.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth mentioning that this is for webpack v2.

@IdanCo
Copy link
Contributor Author

IdanCo commented Apr 23, 2017

@ajacksified , i've explicitly mentioned webpack v2 and put more emphasize on custom variables (after all, why even use webpack if you're not planning on customizing?)

@ajacksified
Copy link

ajacksified commented Apr 23, 2017 via email

@ajacksified
Copy link

Disregard that, misread the notification email. Looks good to me!

implementing PR comments

implementing PR comments
@samsch
Copy link

samsch commented Apr 24, 2017

I would suggest using ExtractTextWebpackPlugin in the example, rather than style-loader. With style-loader, the styles are injected into <style> tags in the html head. With ExtractTextWebpackPlugin, the styles are extracted into a separate css file to be <link>ed in.

The downside is the slightly added complexity, but the upside is less "magic" around importing styles from JS.

@IdanCo
Copy link
Contributor Author

IdanCo commented Apr 24, 2017

@samsch , I agree that using ExtractText in many cases would be the best practice. It's actually used it in the demo project I attached to this PR - https://github.com/IdanCo/webpack-modular/tree/bootstrap4

But I'm not convinced it should be a part of the documentation. There are other best-practices (such as using source maps), but adding them to the documentation might imply that they are essential for compiling Bootstrap, even though they are in no way such. Also, i can think of many use cases in which using ExtractText plugin would be counter productive, such as serving dev server or running tests.

I hope other resources (blogs, stackoverflow, etc.) will expand and elaborate this basic setup. I know I plan to...

@samsch
Copy link

samsch commented Apr 24, 2017 via email

@mdo
Copy link
Member

mdo commented May 2, 2017

Any other feedback before we merge this? (Also, hi @ajacksified! Long time no see! :D)

@Johann-S
Copy link
Member

Johann-S commented May 2, 2017

My only concern about this PR is, is it the role of BS to show how to integrate BS in any plugins, module bundler etc... ?
I know Webpack have a huge community and I love this tool but if we do that we'll have to do for others plugins too so we should create a dedicated page for that on our documentation

@mdo
Copy link
Member

mdo commented May 2, 2017

My only concern about this PR is, is it the role of BS to show how to integrate BS in any plugins, module bundler etc... ?

I think so, yes. I'd love more in-depth and helpful guides for using, extending, and contributing to Bootstrap—regardless of the package manager or community. Bootstrap is meant to be accessible to everyone, beginner or seasoned veteran, so I'm a fan :).

@IdanCo
Copy link
Contributor Author

IdanCo commented May 2, 2017

@mdo totally agree.

@Johann-S i see your point - Bootstrap can't be held responsible for what other bundlers are doing. But on the other hand, the bundlers also can't commit to how Bootstrap is structured (especially while in alpha). So the outcome is that integrations fall "between the chairs". So taking responsibility for documenting may not be the obvious choice, but it will help bring Bootstrap to more people, and i think that's worth it.

Regarding which bundlers should be included, IMO as long as there's a demand for integration documentation, it's worth considering adding.

@Johann-S
Copy link
Member

Johann-S commented May 2, 2017

That's ok for me 👍 it's just a choice to do

@cr101
Copy link

cr101 commented May 2, 2017

We are integrating Bootstrap into our web app with Create React App

@Johann-S
Copy link
Member

Johann-S commented May 3, 2017

I think we can add this page on : Write a Learn & Extend or Approach section.

Related to #17021 (docs section) and #21548

@Johann-S
Copy link
Member

@IdanCo can you update your branch ? because now we use Popper instead of Tether

@IdanCo
Copy link
Contributor Author

IdanCo commented May 15, 2017

Done! and congrats on the huge Popper PR @Johann-S , can't wait to give it a try!

@Johann-S
Copy link
Member

Thank you very much @IdanCo ❤️

$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Tether: 'tether',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change that by Popper ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it

...
{% endhighlight %}

Bootstrap is dependent on jQuery and Tether, so npm will install them for you if needed. But they must be explicitly provided by webpack. Add the following code to the `plugins` section in your webpack config file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change that by Popper ?

@Johann-S
Copy link
Member

LGTM 👍

The merge is up to @mdo because he said :

Looking at this, the only question I have is around the placement of this on a separate page—need to think about that a bit more.

@IdanCo
Copy link
Contributor Author

IdanCo commented May 15, 2017

Changed the webpack configuration to accommodate popper instead of tether.

@Johann-S , any reason why bootstrap.js in v4-dev is not yet updated and still dependent on thether? I built it manually to do my tests and find the correct recipe, but I'm curious about the repo build process...

BTW, at first glance the new tooltips/popovers/dropdown looks great!

EDIT :

Looking at this, the only question I have is around the placement of this on a separate page—need to think about that a bit more.

no problem, let me know if there's anything i can do to help

@Johann-S
Copy link
Member

Johann-S commented May 15, 2017

Yes we build manualy dist files, currently they are outdated but we will update them soon 👍

And thank you for your feedbacks 👍


Import [Bootstrap's JavaScript](/getting-started/javascript/) by adding this line to your app's entry point (usally `index.js` or `app.js`):

{% highlight js %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the triple back tick?

import 'bootstrap';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we use highlight everywhere else due to our Jekyll setup.

@mdo mdo merged commit fc5e8b9 into twbs:v4-dev May 26, 2017
@mdo mdo added this to the v4.0.0-beta milestone May 26, 2017
@mdo mdo mentioned this pull request May 26, 2017
@mdo
Copy link
Member

mdo commented May 26, 2017

Thanks y'all! Holler with PRs if y'all have newer/better ideas for setup docs with other tooling.

@petrpacas
Copy link

@mdo I'd like to point out an issue of compiling the JS with Bootstrap's individual /dist/ files (as hinted here).

I tested @IdanCo's repo and it looks fine when using the bootstrap.js scripts bundle.

However, if you include the /dist/ files individually (and necessarily reference them with ProvidePlugin), the code is duplicated in the resulting JS file (only referencing them in ProvidePlugin and not importing them doesn't work).

The solution for individual imports is, as suggested in the first link, to include the individual /src/ files instead and use a transpiler (Babel etc.).

@IdanCo
Copy link
Contributor Author

IdanCo commented Jul 13, 2017

Thanks @petrpacas , I'll have a look at it this weekend

@mselerin
Copy link

Hi @petrpacas. Personally, I don't use the Provide Plugin but the Expose Loader instead (see my comment here)

Maybe you could adapt your import with this loader and see what happen ?

@petrpacas
Copy link

For those interested, here's my repo with working example of using the individual source files w/ Babel instead:

https://github.com/petrpacas/webpack-bootstrap-4-setup

@ccalvarez
Copy link

Hi.

I followed the guide and for some reason it kept telling me that Tether was needed. I had to replace Popper with Tether.

I've installed Bootstrap with npm install --save [email protected] and in my package.json the dependency is "bootstrap": "^4.0.0-alpha.6",.

How can I get the dependency to Popper as explained in the documentation?
Thanks.

@IdanCo
Copy link
Contributor Author

IdanCo commented Aug 7, 2017

@ccalvarez, These instructions refer to the develop branch which replaced Tether with Popper.

For version Alpha 6 (which you probably use), You can browse the previous commit, or have a look in the issue discussion.

@ccalvarez
Copy link

@IdanCo I understand, thank you very much!

@chrisalexander55
Copy link

Although the documentation is very good, I still found it incomplete regarding the actual NPM packages that need to be installed and interop with other loader(s) who generate source-maps. Here is a Gist that brings it together:

https://gist.github.com/chrisalexander55/81f3d5db057fbcbd74d62d488adbca8a

Please feel free to use this to update the docs page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.