webpack-contrib / expose-loader

Expose Loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compatibility with webpack/webpacker 3?

niedfelj opened this issue · comments

This doesn't appear to be working correctly with the latest webpacker/rails setup, has it been tested with webpack 3? We are using the require format like this:

require('expose-loader?$!jquery')

And not seeing a global $ defined

This specific issue just caused me to waste three hours, so it would be good to either fix the bug, deprecate this package, or put a warning on the README.

EDIT: Apologies, I'm in a mood. Thanks for this FOSS as always, and I don't mean to be ungrateful. It's just hard when things snag you on a deadline. Take care and tysm. <3

webpack3.8.1
came up with the same issue

Same on webpack 3.8.1

same on "webpack": "^3.6.0",

I had this problem again, but just got it to work.

In my pack I have:

require('expose-loader?$!jquery')

In config/webpack/environment.js I have expose-loader set up, and jQuery provided via webpack.ProvidePlugin :

const { environment } = require('@rails/webpacker')

module: {
  rules: [{
    test: require.resolve('jquery'),
    use: [{
      loader: 'expose-loader',
      options: '$'
    }]
  }]
}

const webpack = require('webpack')
environment.plugins.append('Provide', new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery'
}))

module.exports = environment

Current dependencies are:

@rails/webpacker": "^3.0.2",
"expose-loader": "^0.7.5",
"jquery": "^3.3.1",

and

rails (5.2.0)
webpacker (3.4.3)

This require('expose-loader?$!jquery') should do it on its own.

To alternatively configure the expose-loader in config, I use this (feather-icons in this case):

environment.loaders.append('expose', {
  test: require.resolve('feather-icons'),
  use: [{
    loader: 'expose-loader',
    options: 'feather'
  }]
})

and then just the import:

import 'feather-icons';

Looking at the two options, the special require seems better, if a bit funny-looking. But it keeps things in one place.

We fixed a lot of bug for the next release, so it should be work, if you will faced with issue again please open a new issue with reproducible test repo, thanks