I'm having a hard time trying to make Webpack 4 config work. Firstly, I'm not running on a Node.js server; i'm on IIS using .Net MVC. How would I be able to load local js files in my webpack config file?
Here's what my webpack.config.js looks like:
const webpack = require('webpack');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
'ICC.js':
[
path.resolve(__dirname, 'Scripts/dependencies.js'),
path.resolve(__dirname, 'Scripts/ICC/Helpers.js'),
path.resolve(__dirname, 'Scripts/ICC/Layout.js'),
path.resolve(__dirname, 'Scripts/ICC/ICC_Chart.js'),
path.resolve(__dirname, 'Scripts/ICC/AddModDel.js'),
path.resolve(__dirname, 'Scripts/Cache/CacheClientTemplate.js'),
path.resolve(__dirname, 'Scripts/ICC/Menu_ICC.js'),
path.resolve(__dirname, 'Scripts/ICC/ICCObjetLie.js'),
path.resolve(__dirname, 'Scripts/Observable/observable.js'),
path.resolve(__dirname, 'Scripts/Soumission/produitLigne.js'),
path.resolve(__dirname, 'Scripts/Soumission/soumission.js'),
path.resolve(__dirname, 'Scripts/Soumission/livraison.js'),
path.resolve(__dirname, 'Scripts/Soumission/transport.js'),
path.resolve(__dirname, 'Scripts/Soumission/termes.js'),
path.resolve(__dirname, 'Scripts/Soumission/contacts.js'),
path.resolve(__dirname, 'Scripts/Soumission/Recherche/minicart.js'),
path.resolve(__dirname, 'Scripts/Soumission/Recherche/produitRecherche.js'),
path.resolve(__dirname, 'Scripts/Content/content.js'),
path.resolve(__dirname, 'Scripts/Opportunite/competiteur.js'),
path.resolve(__dirname, 'Scripts/Cookie/cookie.js')
]
},
devtool: "source-map",
output: {
filename: '[name]',
path: path.resolve(__dirname, './dist/scripts')
},
module: {
rules:
[
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
parser: {
amd: false, // disable AMD
commonjs: false // disable CommonJS
}
}
],
},
optimization: {
minimize: true,
minimizer: [new UglifyJsPlugin({
uglifyOptions: {
mangle: true,
output: {
comments: false
}
},
sourceMap: true,
exclude: [/\.min\.js$/gi]
})]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
plugins: [
new CleanWebpackPlugin(['./dist'])
]
};
In my dependencies.js, i have the following:
function loaddependencies(scripts) {
for (var i = 0, len = scripts.length; i < len; i++) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = scripts[i];
var x = document.getElementsByTagName('head')[0];
x.appendChild(s);
}
}
var dependencies =
[
"~/Scripts/jquery/jquery.min.js",
"~/Scripts/cldr/cldr.js",
"~/Scripts/cldr/event.js",
"~/Scripts/cldr/supplemental.js",
"~/Scripts/globalize/globalize.js",
"~/Scripts/globalize/message.js",
"~/Scripts/globalize/number.js",
"~/Scripts/globalize/currency.js",
"~/Scripts/globalize/date.js",
"~/Scripts/bootstrap/bootstrap.min.js",
"~/Scripts/splitter/jquery.splitter.js",
"~/Scripts/jquery/jquery.timeago.js",
"~/Scripts/jquery.signalR.min.js",
"~/Scripts/lightbox/js/lightbox.min.js",
"~/Scripts/toolbar/jquery.toolbar.js",
"~/Scripts/dx.all.js",
"~/Scripts/devextreme/dx.aspnet.data.js",
"~/Scripts/devextreme/dx.aspnet.mvc.js",
"~/Scripts/devextreme/localisation/dx.messages.frca.js"
];
loaddependencies(dependencies);
I've tried many solutions before that, such as including the provider plugin to expose jquery globally:
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
with
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
},{
loader: 'expose-loader',
options: '$'
}]
yet that gives me the following error: "require is not defined." (which is normal since i'm not in a Node environment). I've added also
externals: {
jquery: 'jQuery'
}
That didn't work. I've also tried the soluition on the following SO question (solution 3,4,5). It all failed! I've been at this for weeks and I seem to run out of solutions. What in the f*** hell do I have to do make it work?