Skip to main content

Posts

Google Apps Script and ES Modules

Currently, Google Apps Script does not support ES modules - and any usage of export/import will fail. One way of handling this is to use rollup.js to bundle your project into one single JavaScript file. The trick here is to make sure not to export any functions in your entry point code, e.g. index.ts , and to prevent any generation of export statement in the final bundle (see the custom rollup plugin in the rollup.config.js below). import { babel } from "@rollup/plugin-babel"; import { nodeResolve } from "@rollup/plugin-node-resolve"; const extensions = [".ts", ".js"]; const preventThreeShakingPlugin = () => { return { name: 'no-threeshaking', resolveId(id, importer) { if (!importer) { // let's not theeshake entry points, as we're not exporting anything in Apps Script files return {id, moduleSideEffects: "no-treeshake" } } return null; }...
Recent posts

Stop rolling your own Webpack configuration!

So you have your custom frontend project with a huge webpack configuration file, while enviously looking at some newer code bases based on Create React App from Facebook? Or, you've started out with a vanilla Create React App, but felt that you needed to eject (even though many advised you not to)? Either way, wouldn't it be nice to be able to re-use some of that magic in a dependency-kind-of-way? After all, Facebook's configuration is probably more tested and thought-through than yours! :) Well, you can! All that Webpack magic, incl. Jest and Webpack Dev Server configuration, is packaged by Facebook in react-scripts . Internally, Create React App is using it, but that doesn't help us, right? In this post, I'll show you how. In order to be able to tap into react-scripts we first need to install them as a dependency using npm install react-scripts --save-dev . This is where the fun begins! In essence, you create a webpack.shared.config.js and import the ba...

Web API with ASP.NET Core MVC

I was exploring the new ASP.NET Core from Microsoft and being on a Mac, to start things off, I was following this guide, which includes setting up .NET Core and Visual Studio Code with the C# extension + scaffolding a template project using Yeoman. Pretty simple and works out of the box. Now, to get going with Web API, the next guide would be https://docs.asp.net/en/latest/tutorials/first-web-api.html. However, this is based on Visual Studio 2015, where there are ready-made templates for a Web API project. I continued using the guide with my Yeoman template to see how far it would take me. Turns out that I got pretty far, by just following the examples. The first thing that hit me was the change in the ConfigureServices file, namely the services.AddMvc(); method. There was no notion of a MVC-framework in the generated Yeoman code, and I had to add "Microsoft.AspNetCore.Mvc": "1.0.0" to project.json to make it compile. To finally get the application to ...

Locked rotation on Ipad - The Last Resort

I've been having a lot of issues over the past year with my Ipad's rotation being locked. I think I've been through every support page, blog and even youtube videos in search for a solution. Sure, I've been reading about all the obvious stuff, like checking that "Lock Rotation" isn't enabled (either through swiping up to get to the shortcut menu, or through the side switch option), or rebooting the device by pressing the home and lock screen button for about 10 sec. In fact, rebooting used to work most of the time, but only if I made sure to quit all running applications before doing it. I.e. double-click the home button and swipe up on all open applications. Seems like some applications manage to lock the rotation indefinitely. Anyway, this time it's not working! Once in a while, it starts working for a day, or two, and then it's locked again. It usually starts working after an iOS update, like the latest 8.1.1, but soon starts locking again. ...

Handlebars integration with Yeoman’s webapp-generator

I was looking for an instruction on how to add Handlebars to my application based on Yeoman’s webapp-generator. There is an instruction on the old wiki on GitHub, but it’s out-of-date. For this exercise I’ve been using Yeoman 1.1.2 and the 0.47 version of the webapp-generator. First off, go ahead with step 1 and 2 (but obviously using the latest versions). There’s no need to load the "grunt-contrib-handlebars" in your Gruntfile.js (step 3), as "require('load-grunt-tasks')(grunt);" is used to load all referenced tasks. I did some changes to the file structure in step 4, but I guess that’s a matter of taste? One thing to note is the change from “temp” to “.tmp” as this is the temporary directory name being used in other places: handlebars: { compile: { files: { '.tmp/scripts/compiled-templates.js': [ '<%= yeoman.app %>/templates/**/*.hbs' ] }, options: { namespace: 'MyApp.Templates...

Loading Google Maps API asynchronously with RequireJS

With Single Page Web Applications becoming more and more popular, I decided to understand the concepts of various Javascript frameworks a little better. There are literally hundreds of them, but I decided to start with a really nice tutorial written by Alex Young. Cornerstones in this tutorial are BackboneJS, Underscore, Bootstrap and RequireJS. After been through the tutorial I decided to roll my own project based on the same setup. I wanted to use Google Maps for this, and searched for a way to load the API using RequireJS. Turned out that there are a few different approaches, but the most common seems to be to use the async-plugin created by Miller Medeiros. Jason Wyatt has another interesting solution which caught my attention. Being new to all this, I really didn't feel like start involving plug-ins from remote repositories. It might be the most natural thing to do, but one step at a time is more my melody. Jason's solution had some drawbacks mentioned in the comm...

Greasemonkey to rescue!

Greasemonkey is an add-on to Firefox that seems to prove to be really useful, so I wanted to give it a spin. Basically, what it does is to modify webpages on-the-fly as you load them - using JavaScript. Many times I guess people use it to get rid of nasty ads and so forth. There are plenty of other add-ons able to do that - like removing a specific element each time, which doesn't require any coding. What fun is that? Nonetheless, my first Greasemonkey-script does just that - removes an ad. But for the site in question - www.di.se (all in Swedish) - it isn't as easy as removing an element. The site is divided into 3 rows using a frameset that looks like this:   <frameset frameborder="no" framespacing="0" rows="0,210,*"> <frame class="noprint" frameborder="no" framespacing="0" name="historyFrame" noresize="" scrolling="no" src=""></frame> <fram...