Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor import CommonJS modules #52

Open
zce opened this issue Jul 23, 2021 · 0 comments
Open

Refactor import CommonJS modules #52

zce opened this issue Jul 23, 2021 · 0 comments
Labels

Comments

@zce
Copy link
Owner

zce commented Jul 23, 2021

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 label Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant