Skip to content

Instantly share code, notes, and snippets.

@hungdoansy
Created March 22, 2023 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hungdoansy/436a26fc5c69969d9d29cd531af297ce to your computer and use it in GitHub Desktop.
Save hungdoansy/436a26fc5c69969d9d29cd531af297ce to your computer and use it in GitHub Desktop.

File package.json

    {
    "main": "index.js",
    "script": {
        "build": "babel src -d build --copy-files",
        "start": "rm -rf build && yarn build && node build/index.js"
    },
    "dependencies": {
    "@babel/cli": "7.15.7",
    "@babel/core": "7.15.8",
    "@babel/preset-env": "7.15.8",
    "core-js": "3.18.2",
    "regenerator-runtime": "0.13.9",
    "babel-plugin-module-resolver": "4.1.0",
    }
  }

File jsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2016",
        "baseUrl": "./src",
        "rootDir": "."
    },
    "include": ["src/**/*.js"],
    "exclude": ["node_modules"]
}

File .babelrc.js

const path = require("path");
const jsConfig = require("./jsconfig.json");

module.exports = {
    presets: ["@babel/preset-env"],
    plugins: [
        [
            "module-resolver",
            {
                root: [path.resolve(jsConfig.compilerOptions.baseUrl)],
            },
        ],
    ],
};

File index.js

import 'core-js';
import 'regenerator-runtime/runtime';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment