js-stack-from-scratch icon indicating copy to clipboard operation
js-stack-from-scratch copied to clipboard

Webpack, bootstrap and pre-loading jquery

Open gaitat opened this issue 8 years ago • 1 comments

Type of issue: (feature suggestion, bug?)

suggestion

Chapter:

8

In chapter 8 you suggest using this code in order to include bootstrap in a project.

import $ from 'jquery'
import Tether from 'tether'

window.jQuery = $
window.Tether = Tether
require('bootstrap') 

Is there a reason not to use the following code that preloads jquery and tether so that you can just do import 'bootstrap'; in the project?

new webpack.ProvidePlugin({
  $: "jquery",
  jQuery: "jquery",
  "window.jQuery": "jquery",
  Tether: "tether",
  "window.Tether": "tether",
}),

The only drawback I have found is that eslint complains about $ being undefined but that can be solved by adding in .eslintrc.json the following:

  "env": {
    "jquery": true
  },

gaitat avatar May 04 '17 00:05 gaitat

That is probably a cleaner way to do it, thanks for bringing it up :)

verekia avatar May 04 '17 00:05 verekia