I am trying to access jquery in my application according to information on webpack website you are able to create global variable using webpack https://webpack.js.org/plugins/provide-plugin/
here is my webpack set up
module.exports = {
entry: {
index: "./scripts/index.js",
vendorJS: ["jquery", "jquery-validation", "jquery-validation-unobtrusive"]
}
,
output: {
path: path.join(__dirname, '/wwwroot/'),
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.scss', '.sass']
},
module: {
rules: [
{
test: /\.scss$/i,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.css$/i,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader']
})
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['url-loader?limit=10000&mimetype=application/font-woff&name=/fonts/[name].[ext]'],
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['file-loader?name=/fonts/[name].[ext]'],
}
]
},
plugins: [
new CleanWebpackPlugin(['./wwwroot']),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
}),
css
],
}
using thius set up i am unable to access my $ - jquery in console menu.
any idea why this is happening?
I know it's late, but for Googlers (or Duck Duck goers if you care about privacy), I had the same problem:
if I used $: 'jquery'
It threw
Can't resolve 'jquery'
If I used
const jquery = require('jquery');
$: jquery
It threw
Can't import module "undefined"
This finally worked for me:
new webpack.ProvidePlugin({
$: require.resolve('jquery'),
jQuery: require.resolve('jquery')
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With