Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Refactor import CommonJS modules #4

Open
zce opened this issue Aug 5, 2020 · 0 comments
Open

Refactor import CommonJS modules #4

zce opened this issue Aug 5, 2020 · 0 comments
Labels
question Further information is requested

Comments

@zce
Copy link
Owner

zce commented Aug 5, 2020

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:

@zce zce added the question Further information is requested label Aug 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant