When I run webpack, my javascript assets are not complied in the correct order. The correct order should be
- Jquery
- Bootstrap
However the complied bundle file contains Bootstrap first then Jquery. Please see below
webpack.config
var path = require('path');
var webpack = require('webpack');
var extractTextPlugin = require('extract-text-webpack-plugin');
var cleanWebpackPlugin = require('clean-webpack-plugin');
var jsDestPath = './wwwroot/';
const config = {
entry: {
css: './Assets/scss/app.scss',
app: './Assets/js/app.js',
vendor: './Assets/js/vendor.js'
},
output: {
path: path.resolve(__dirname, 'wwwroot/js'),
filename: '[chunkhash].[name].js'
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader'
},
{
test: /\.scss$/,
loader: extractTextPlugin.extract({
loader: 'css-loader!sass-loader'
})
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'] //Specify the common bundle's name.
}),
new extractTextPlugin({ filename: 'bundle.css', disable: false, allChunks: true}),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: true,
}
}),
new cleanWebpackPlugin(['js'], {
root: jsDestPath,
verbose: true,
dry: false
})
],
}
module.exports = config;
vendor.js
import 'jquery/dist/jquery.js';
import 'bootstrap/dist/js/bootstrap.js';
The order in which modules are present in the webpack output do not necessarily mean that is the order in which they are loaded. webpack will not load (execute) the jQuery module before it is required/imported in the code. In reality, you will see that the execution order will still be correct.