(221) Convert concatenated strings into modern template strings Media Query Listeners (223)

VS Code: Easily convert require statements into modern ES module imports

7th May 2020
Easily convert require statements into modern ES module imports

Convert your require()'s into ES Module imports by clicking the 💡️ lightbulb icon and selecting 'Convert to ES6 module'. Using this feature can convert your code from this:

const path = require('path');
const crypto = require('crypto');

const fetch = require('node-fetch');
const {name} = require('./animal.js');

Into this:

import path from 'path';
import crypto from 'crypto';

import fetch from 'node-fetch';
import { name } from './animal.js';

As a bonus, this also works with exports!

I also shared this on twitter!

Sign up to receive a developer tip, in the form of a gif, in your inbox each week