GithubHelp home page GithubHelp logo

如何调试 ES6 modules ? about node-in-debugging HOT 2 OPEN

nswbmw avatar nswbmw commented on September 27, 2024
如何调试 ES6 modules ?

from node-in-debugging.

Comments (2)

mantou132 avatar mantou132 commented on September 27, 2024

这里改了官方文档中的 custom-loader.js:

import url from 'url';
import path from 'path';
import process from 'process';
import Module from 'module';

const builtins = Module.builtinModules;
const JS_EXTENSIONS = new Set(['.js', '.mjs']);

export function resolve(specifier, parentModuleURL = 'file://', defaultResolve) {
  console.log(specifier, parentModuleURL);
  if (builtins.includes(specifier)) {
    return {
      url: specifier,
      format: 'builtin'
    };
  }
  if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
    // For node_modules support:
    return defaultResolve(specifier, parentModuleURL);
    // throw new Error(
    //   `imports must begin with '/', './', or '../'; '${specifier}' does not`);
  }
  const resolved = new url.URL(specifier, parentModuleURL);
  const ext = path.extname(resolved.pathname);
  let result = resolved.href;
  if (!JS_EXTENSIONS.has(ext)) {
    // throw new Error(
    //   `Cannot load file with non-JavaScript file extension ${ext}.`);
    result = resolved.href + '.js';
  }
  return {
    url: result,
    format: 'esm'
  };
}

from node-in-debugging.

nswbmw avatar nswbmw commented on September 27, 2024

在 Node.js 没有完全支持 ES6 modules 之前不会添加这个 case...

from node-in-debugging.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.