When a dependency specifier references one of these module names, the builtin module is preferred over any module installed in node_modules with the same name. Parcel includes shims for many builtin Node.js modules, e.g. This could be a node_modules/lodash/clone.js file, for example. The above example resolves lodash within a node_modules directory as described above, and then resolves the clone module within the package rather than its main entrypoint. For example, a package may publish multiple entry points rather than only a single one. Package sub-paths #īare specifiers may also specify a sub-path within a package. See Package entries for more details on this process. Once a module directory is found, the package entry is resolved. /path/to/project/src/node_modules/react./path/to/project/src/client/node_modules/react.For example, if the importing file was at /path/to/project/src/client/index.js the following locations would be searched: The search stops at the project root directory. Node_modules directories are searched upwards from the importing file. The exact location will depend on the location of the node_modules directory, as well as configuration within the package. In the above example, react may resolve to something like /path/to/project/node_modules/react/index.js. path/to/project/src/client/index.js: import 'react' All extensions listed above are supported for index files. If no package.json is present, it will attempt to resolve to an index file within the directory, such as index.js or index.ts. If the directory contains a package.json file, the main entry will be resolved as described in the Package entries section. In JavaScript, Typescript, and other JS-based languages, dependency specifiers may resolve to a directory rather than a file. foo.js exists, it will be used instead of the TS version, matching the behavior of Node and other bundlers. In TypeScript files, Parcel will also try replacing JavaScript extensions including. File extensions are always required for dependencies defined in other file types like HTML and CSS. Note that these may only be omitted when importing from a JavaScript or TypeScript file. path/to/project/src/client.js: import './utils' , and resolve a file relative to the importing file. In addition to the standard dependency specifiers supported across many tools, Parcel also supports some additional specifier types and features. It is responsible for turning a dependency specifier into an absolute path that can be loaded from the file system. Parcel implements an enhanced version of the Node module resolution algorithm. Typically, these dependencies do not specify a full absolute path, but rather a shorter specifier that is resolved to an absolute path by Parcel and other tools. For example, in JavaScript the import statement or require function may be used to create dependencies. Dependency specifiers #Ī dependency specifier is a string that describes the location of a dependency relative to the file that imports it. Dependencies describe where to find the file containing the code you rely on, as well as metadata about how to build it. As Parcel builds your source code, it discovers dependencies, which allow code to be broken into separate files and reused in multiple places.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |