Root directory in package.json

前端 未结 7 1666
臣服心动
臣服心动 2020-12-25 10:25

My question concerns an existing library that I wish to publish as an NPM module. The library is already in use, and currently required via the local file syste

7条回答
  •  借酒劲吻你
    2020-12-25 11:17

    Another possibility is to use ECMAScript modules (ES modules), particularly the package exports field in your package.json file.

    Given a package.json file with this config:

    {
      "name": "my",
      "exports": {
        "./": "./src/js/lib/my/"
      }
    }
    

    You should be able to import modules from the library like:

    import thing from 'my/thing'
    import that from 'my/that'
    

    This is enabled by default since node 13.0.0, but was behind the --experimental-exports flag from 12.13.0.

    Note, that the ES Module spec is in the Stability:1 - Experimental stage and subject to change. I have no idea the extent to which this might be compatible with CommonJS modules.

提交回复
热议问题