Debugging Webpack

This has caused me several days of exciting times… some of the errors Webpack gives can be a little misleading, showing one error when there’s in-fact a totally different underlying issue which will fix everything!

The following shows you everything you need;

<./node_modules/.bin/encore (or your command here> --watch --progress --display-error-details --verbose

You’ll need to replace the start of this command with something relevant to you, depending on the location of your encore / webpack executable.

Webpack Encore & CometD

This drove me nuts for hours;

These dependencies were not found:
* org/cometd in ./node_modules/cometd-jquery/jquery/jquery.cometd.js

The solution … in your webpack.config.js file;

config = Encore.getWebpackConfig();
config.resolve.alias["org/cometd"] = path.resolve(__dirname, "./node_modules/cometd-jquery/org/cometd");
config.resolve.alias["jquery.cometd"] = path.resolve(__dirname, "./node_modules/cometd-jquery/jquery/jquery.cometd");

// export the final configuration
module.exports = config;

After that you should be all good to go!

If you get an error about the ‘path’ function not existing, then just include the following at the top of the file;

var path = require('path');

Responsive images

 <source media="(max-width: 768px)" srcset="path/to/img-small.png">
 <source media="(min-width: 768px)" srcset="path/to/img-big.png">

Not supported in IE though 🙁

jQuery Book – Basics through to Performance Optimisations

A few things to note;

  • When using selectors with ID tags, use $(‘#abc’).find(‘.defg .higk’); instead of $(‘#abc .defg .higk’);
  • Also use named functions more-so than anonymous ones;
    var PI = {
    onReady : function() {
    $(‘#happiness’).load(PI.url + ‘ #unicorns’, PI.unicornCb);
    candyMtn : function(e) {
    slideCb : function() { … },
    unicornCb : function() { … }
  • Plugin creation;
    // defining the plugin
    $.fn.hoverClass = function(c) {
    return this.hover(
    function() { $(this).toggleClass(c); };
    }(jQuery);// using the plugin
  • see here for signs of poorly written plugins;
  • See here for details on plugin development;



DataTables – post row-rendering;

$(document).ready(function() {
$(‘#example’).dataTable( {
“fnRowCallback”: function( nRow, aData, iDisplayIndex ) {
/* Bold the grade for all ‘A’ grade browsers */
if ( aData[4] == “A” )
$(‘td:eq(4)’, nRow).html( ‘<b>A</b>’ );
return nRow;
} );
} );

More bed-time reading – looks to be of some use as well for multiple search fields (eg. text field and dropdown box and this and that, etc). is something also to implement for keeping track of which rows were selected\ initial column sorting

  "aaSorting": [[ 2, "asc" ]]