Tuesday, July 14, 2015

Visual Studio Code for Linux

Code: A Visual Studio for Linux.  Now I understand how Alice must have felt in Wonderland.

Code is a preview with only 2 releases under it's belt. And it's quickly becoming my favorite javascript editor. It's blazingly fast. I hate slow code editors. And it has Intellisense! The biggest thing missing is a quick way to preview my web page. But I can work around that:
  1. $ cd MyProject
  2. $ npm install --save-dev superstatic
  3. $ npm install --save-dev open
  4. Edit the file .settings/launch.json. If this file doesn't exist, hit F5, and a new template will be created.
  5. Change "program": "main.js" to "program": "bin/server.js",
  6. Then create bin folder and the file bin/server.js (code below)
Now, when you hit the F5 key, you can preview your web page in your default browser. This works for me on both Linux Mint and Windows 7.

Assuming that my project has a web/index.html as the main page:

/**
 * Run a static server
 */
var server = require('superstatic').server;
var open = require('open');
var path = require('path');

var options = {
 port: 3474,
 host: 'localhost',
 config: {
  root: './web',
  routes: {
   '/': 'index.html'
  }
 },
 cwd: path.resolve(__dirname, '..'),
 debug: false 
};

server(options).listen(function(err) {
 open('http://localhost:3474');
});

No comments:

Post a Comment