sandoche / Jekyll-webpack-boilerplate

⚡️ A boilerplate with Jekyll and Webpack to make the most performant static websites
MIT License
188 stars 57 forks source link

Problem including jQuery plugin #10

Closed malmr closed 5 years ago

malmr commented 5 years ago

Hey,

thank you very much for your helpful boilerplate. Im facing a problem when I try to use jQuery in the navigation.html file, the console outputs

ReferenceError: $ is not defined

I installed jQuery with npm i jquery --save. Then I adjusted the config/webpack.common.js by adding:

const webpack = require('webpack'); ... plugins: [
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),

I also tried to use jQuery in the index.js file, but resulting in the same error. What am I missing? Thanks in advance!

banavasi commented 5 years ago

Same problem here. Thanks in advance

sandoche commented 5 years ago

Have you tried restarting the dev server? Does the use of 'jquery' without the '$' works?

Here they say that you also need to put this in your index.js

import $ from 'jquery';  
window.jQuery = $; window.$ = $;

https://github.com/webpack/webpack/issues/4258

malmr commented 5 years ago

Thank you @sandoche. With this config im getting following error: window is not defined But this can simply be fixed by adjusting eslintrc.js:

const config = {
  "extends": "airbnb-base",
  "env": {
    "browser": true,
    "node": true,
    "jasmine": true
  },
};