У меня есть следующий код в моем webpack.config.js согласно документам :
const nodeFolder = 'C:\\Program Files (x86)\\Microsoft VS Code\\bin\\node_modules\\';
...
new webpack.ProvidePlugin({
//$: 'jquery', tried this and the next one
$: nodeFolder + 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
Но когда яПопробуйте использовать его в одном из моих модулей, я получаю следующую ошибку: Unable to resolve path to module 'jquery'
.Я проверил папку в папке bin и там есть папка jquery.
Я понимаю, что, поскольку у меня есть универсальная папка node_modules, я усложняю жизнь, но это решение не в моих руках.
Вот весь конфигурационный файл для справки:
const webpack = require('C:\\Program Files (x86)\\Microsoft VS Code\\bin\\node_modules\\webpack');
const path = require('C:\\Program Files (x86)\\Microsoft VS Code\\bin\\node_modules\\path');
const nodeFolder = 'C:\\Program Files (x86)\\Microsoft VS Code\\bin\\node_modules\\';
const currentEnv = process.env.NODE_ENV || 'development';
const isProduction = currentEnv === 'production';
//console.log(`Building for Production ${isProduction}`);
module.exports = {
mode: currentEnv,
entry: path.join(__dirname, 'App_Themes\\blah\\scripts\\common2.js'),
watch: true,
output: {
path: path.join(__dirname, 'App_Themes\\blah\\scripts\\'),
filename: "common2.min.js"
},
resolveLoader: {
modules: [nodeFolder]
},
resolve: {
modules: [nodeFolder]
},
module: {
rules: [
{
test: /\.js$/,
loader: 'eslint-loader',
enforce: 'pre',
// include: [path.resolve(__dirname, '/App_Themes/blah/scripts/')],
options: {
formatter: require(nodeFolder + 'eslint-friendly-formatter'),
failOnError: true
},
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [nodeFolder + '@babel/preset-env'],
},
},
},
],
},
plugins: (() => {
const common = [
new webpack.ProvidePlugin({
// $: 'jquery',
$: nodeFolder + 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
ekkoLightbox: 'ekko-lightbox',
}),
];
const development = [];
const production = [];
return isProduction ? common.concat(production) : common.concat(development);
})(),
devtool: 'source.map',
};