Control Add-ins Supercharged: Development and production build tasks

  • Reading time:2 mins read

I’ve been absent for a while – sometimes it’s difficult to find time for blogging even when I want it. Anyway… here’s the last post in the introductory series of posts that explain my NAV TechDays 2019 demos. In this code example, I explain the difference between typical development and production build configurations, and I show how to configure gulp accordingly.

To check the code example, and to read the detailed explanations of it, jump over to https://github.com/vjekob/supercharged_01/tree/08-gulp-build-prod

Continue ReadingControl Add-ins Supercharged: Development and production build tasks

Control Add-ins Supercharged: Babel

  • Reading time:1 min read

After a short absence, I am back. The next lesson in the Control Add-ins Supercharged series I am introducing Babel.

“Babel is a JavaScript compiler”, says babeljs.io. So, what’s the big deal, you may ask? The big deal is that Babel will take your super-fancy high-end future-generation JavaScript code that barely any browser supports, and turn it into something that even Internet Explorer can run. In theory, at least. In practice, it’s a bit more complicated.

To learn about theory and practice of Babel in control add-in development workflows, check this branch: https://github.com/vjekob/supercharged_01/tree/07-gulp-babel

And that’s it. The Readme.md file contains all the theory and practice you need. So, navigate to my github and check it out.

Continue ReadingControl Add-ins Supercharged: Babel

Code annotations in AL – Please, don’t!

  • Reading time:10 mins read

One of good practices of writing C/AL Code for Microsoft Dynamics NAV since the dawn of civilization was annotating (commenting) code changes. If you are not sure what I mean by that, this is what I am talking about:

While standards varied about > vs +, or < vs -, or what the annotations should include, there was absolute consensus that annotating changes is an absolute must.

And it was a must. It was such an important rule that everyone followed it without questions asked. In my career, I’ve seen one or two situations of somebody changing or deleting a line of code without leaving any comment, and I’ve seen quite a lot of code, believe you me. It was that important.

It was that important in fact that it was one of the first things developers learned when they signed up for the job, and it was one of the rules they all followed from their first day.

Continue ReadingCode annotations in AL – Please, don’t!

Control Add-ins Supercharged: Debugging with source maps

  • Reading time:3 mins read

So far I’ve shown how to configure gulp to help you with some basic JavaScript development tasks, such as bundling and minifying, and how to automate builds on every source file change. Let’s now take it to an entirely new level: debugging.

If you ever tried to debug your control add-in source code using Visual Studio Code, you might have realized two things: first, that it’s actually pretty simple to do; and second, that it’s not the kind of debugging that you want.

Let’s see why that is.

First, using VS Code with a browser such as Chrome, Edge (especially “Canary”, mmmm) or Firefox is easy. There are debugging extensions built for that purpose that allow you to either launch a browser with VS Code attached as a debugger, or to attach VS Code to a running instance of a browser (some browser configuration needed beforehand). However, when you use VS Code as a debugger like this, it’s hardly more than a glorified browser built-in developer tool – the only benefit of using VS Code is that, well, you are in VS Code, rather than inside the browser. However, you are not really debugging your source files – you are debugging scripts currently loaded in the browser. You can’t set debug breakpoints in your source files – you can only set them in copies of files that are loaded by the browser. If you catch a bug (kind of a point with a debugger) you can’t stop the process and immediately change the line where the bug is, but you have to first locate the matching source script, and then the offending line, and then fix it there. Not exactly a fun pastime.

And that’s annoying enough if you have a single script to work with, but if you have several scripts, bundled together, then minified, well, good luck with that. Debugging minified code is as close as you can get to inquisition-level torture in this century.

So, let’s fix this mess, and let’s enable debugging as it should be – let’s enable debugging of actual source files with full breakpoint integration and all.

That’s what my next branch is about. In it, I introduce source maps and how you can use gulp to build them. And then I explain how you can configure your VS Code to debug your source files.

So, head over to https://github.com/vjekob/supercharged_01/tree/06-gulp-debug and check out some pretty cool stuff.

Continue ReadingControl Add-ins Supercharged: Debugging with source maps

Control Add-ins Supercharged: Automating gulp.watch

  • Reading time:2 mins read

Yesterday you’ve seen how to use gulp to make it do something truly useful: bundling your JavaScript and CSS files. Introducing gulp for the purpose of bundling your files allows you to split your functionality into as many files as you want, but use only a single script and a single stylesheet file from your control add-in. That way you not only optimized how your browser loads the files, but you also eliminated the need to maintain your controladdin object file every single time a new JavaScript or CSS file is added (or an existing one is removed).

However, you still need to run gulp build every single time you want to build your bundles. If you forget that, your controladdin will not be updated with your changes.

Thankfully, gulp has an answer to this: the gulp.watch feature. That’s the topic of my next demo, that I’ve explained in the 05-gulp-watch branch of my supercharged-01 repository.

The Readme.md file of that branch explains how to configure the watch task in the gulpfile.js file, and how to configure VS Code to automatically run the watch task every time you open the workspace. Once you follow those instructions, you can work on individual JavaScript or CSS files without the need to run gulp build or to maintain your controladdin object file. The former is taken care of by gulp, and the latter is taken care by… well, gulp too. Gulp is cool, really 😎

Continue ReadingControl Add-ins Supercharged: Automating gulp.watch

Control Add-ins Supercharged: Teaching gulp some useful tricks

  • Reading time:1 min read

My last demo introduces gulp, an amazingly simple task automation tool. You’ve seen what it is, how to set it up, and how to create a simple hello-world task. Now it’s time to teach gulp some useful tricks and make it automate the “build” process for the JavaScript and CSS files.

The first demo in this series uses a single-file approach, and there I stated that it’s a bad thing to develop like that. It’s bad to put all the functionality in one single file. However, that rule applies for development, not for runtime. Your browser actually prefers using a smaller number of JavaScript (or CSS) files. That’s why typical runtime JavaScript libraries are bundled. On top of bundling, you’ll also want to minify your JavaScript and CSS files to make them as small as possible, to further improve the download and initialization speed.

These are the things that today’s demo uses. So, head over to the https://github.com/vjekob/supercharged_01/tree/04-gulp-useful branch, and check out how to configure your gulp to build your JavaScript and CSS bundles from your source files.

Continue ReadingControl Add-ins Supercharged: Teaching gulp some useful tricks