Git Product home page Git Product logo

learning's People

Contributors

dependabot[bot] avatar gavinhe322 avatar moringstart-hao avatar qinhui1003 avatar

Stargazers

 avatar

Watchers

 avatar

learning's Issues

module.createRequire

新增于: v12.2.0

  • 返回: require 函数。

记录原因

  • 网上的例子太少,不清晰(google、baidu)
  • vue-climodule 使用该api编写
  • 文档表示返回一个 require,但是一直遇到 { a: false } 之类的

问题

  • 为什么一直显示 {a: false}
  • 后来回想 vue-cli 是执行完 npm.install,然后才 require("@vue/cli-plugin-router/generator") 之类的,然后引入的应该是 node_module 中的模块,如此才正常使用

步骤

  • npm init -y
  • npm i debug -D
// a.js
module.exports = { a: 'a' }

// module.js
const { createRequire } = require('module')
const path = require('path')

const a = createRequire(path.resolve(__dirname, 'package.json'))('./a') // { a: false }
const debug = createRequire(path.resolve(__dirname, 'package.json'))('debug')
const ms = createRequire(path.resolve(__dirname, 'package.json'))('ms')

console.log(a)   // { a: false }
debug('bug')('???') // bug ??? +0ms
console.log(ms('2 days'))  // 172800000

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.