zce/caz

Refactor import CommonJS modules

zce opened this issue · 0 comments

zce commented

At present, all modules are imported directly using the import statement, such as:

import fs from 'fs'
import pkg from './package.json'

output code

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const package_1 = __importDefault(require("./package"));

__importDefault is too redundant.

Maybe import = require() is a better choice for the commonjs module, such as:

import fs = require('fs')
export const contents = fs.readFileSync(...)

output code

var fs_1 = require("./fs");
exports.contents = fs_1.readFileSync(...)

ref: