You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+85-46Lines changed: 85 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,29 +77,32 @@ await writeImportMapFiles({
77
77
"./importmap_for_dev.importmap": {
78
78
mappingsForNodeResolution:true,
79
79
mappingsForDevDependencies:true,
80
-
checkImportResolution:true,
81
80
},
82
81
"./importmap_for_prod.importmap": {
83
82
mappingsForNodeResolution:true,
84
-
checkImportResolution:true,
85
-
removeUnusedMappings:true,
86
83
},
87
84
},
88
85
})
89
86
```
90
87
91
88
## projectDirectoryUrl
92
89
93
-
_projectDirectoryUrl_ parameter is a string url leading to a folder with a _package.json_.
94
-
This parameters is **required** and accepted values are documented in [@jsenv/filesystem#assertAndNormalizeDirectoryUrl](https://github.com/jsenv/filesystem/blob/main/docs/API.md#assertandnormalizedirectoryurl)
90
+
_projectDirectoryUrl_ is a string/url leading to a folder with a _package.json_.
91
+
92
+
_projectDirectoryUrl_ is **required**.
95
93
96
94
## importMapFiles
97
95
98
-
_importMapFiles_ parameter is an object where keys are importmap file relative urls and values are parameters controlling the mappings that will be written in the importmap file.
96
+
_importMapFiles_ is an object where keys are file relative urls and value are objects configuring which mappings will be written in the importmap files.
97
+
98
+
_importMapFiles_ is **required**.
99
99
100
100
### mappingsForNodeResolution
101
101
102
-
When _mappingsForNodeResolution_ is enabled, the mappings required to implement node module resolution are generated.
102
+
_mappingsForNodeResolution_ is a boolean. When enabled mappings required to implement node module resolution are generated.
103
+
104
+
_mappingsForNodeResolution_ is optional.
105
+
103
106
The following source of information are used to create complete and coherent mappings in the importmap.
104
107
105
108
- Your _package.json_
@@ -110,97 +113,130 @@ The following source of information are used to create complete and coherent map
110
113
111
114
### mappingsForDevDependencies
112
115
113
-
When enabled, `"devDependencies"` declared in your _package.json_ are included in the generated importMap.
116
+
_mappingsForDevDependencies_ is a boolean. When enabled, `"devDependencies"` declared in your _package.json_ are included in the generated importMap.
114
117
115
-
### manualImportMap
118
+
_mappingsForDevDependencies_ is optional.
116
119
117
-
_manualImportMapp_ parameter is an importMap object. Mappings declared in this parameter are added to mappings generated for node resolution. This can be used to provide additional mappings and/or override node mappings.
118
-
This parameter is optional and by default it's an empty object.
120
+
### runtime
121
+
122
+
_runtime_ is a string used to determine what to pick in [package.json conditions](https://nodejs.org/docs/latest-v16.x/api/packages.html#packages_conditions_definitions).
123
+
124
+
_runtime_ is optional and defaults to `"browser"`.
_checkImportResolution_ is a boolean parameter controlling if script tries to resolve all import found in your js files using the importmap.
146
+
_packageUserConditions_ is an array controlling which conditions are favored in [package.json conditions](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_conditions_definitions).
141
147
142
-
It is recommended to enable this parameter, it gives more confidence in the generated importmap and outputs nice warnings in case some import cannot be resolved.
148
+
_packageUserConditions_ is optional.
143
149
144
-
The import resolution starts from your project entry point which is determined using your package.json "exports" or "main" field.
This import resolution check is auto enabled when [removeUnusedMappings](#removeUnusedMappings) or [extensionlessAutomapping](#extensionlessAutomapping) are used.
_removeUnusedMappings_ parameter is a boolean controlling if mappings will be treeshaked according to the import found in your files.
170
+
_manualImportMap_ is an object containing mappings that will be added to the importmap. This can be used to provide additional mappings and/or override node mappings.
151
171
152
-
During development, you can start or stop using a mapping often so it's convenient to have all mappings.
172
+
_manualImportMap_ is optional.
153
173
154
-
In production you likely want to keep only the mappings actually used by your js files. In that case enable removeUnusedMappings: it will drastically decrease the importmap file size.
_entryPointsToCheck_ is an array composed of string representing file relative urls. Each file is considered as an entry point using the import mappings. For each entry point, _writeImportMapFiles_ will check if import can be resolved and repeat this process for every static and dynamic import.
157
195
158
-
A string parameter indicating where the importmap will be used. The default runtime is `"browser"`.
159
-
The runtime is used to determine what to pick in [package.json conditions](https://nodejs.org/docs/latest-v16.x/api/packages.html#packages_conditions_definitions).
It is recommended to use _entryPointsToCheck_ as it gives confidence in the generated importmap. When an import cannot be resolved, a warning is logged.
180
213
181
-
Controls which conditions are favored in [package.json conditions](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_conditions_definitions).
214
+
### removeUnusedMappings
215
+
216
+
_removeUnusedMappings_ is a boolean. When enabled mappings will be treeshaked according to the import found in js files. It must be used with _entryPointsToCheck_.
During development, you can start or stop using a mapping often so it's convenient to have all mappings.
234
+
235
+
In production you likely want to keep only the mappings actually used by your js files. In that case enable removeUnusedMappings: it will drastically decrease the importmap file size.
236
+
201
237
### extensionlessAutomapping
202
238
203
-
_extensionlessAutomapping_ parameter is a boolean controlling if mappings are generated for import(s) without extension found in your js files. Should be combined with _magicExtensions_ as shown in the code below.
239
+
_extensionlessAutomapping_ is a boolean. When enabled mappings are generated for import(s) without extension found in your js files. It must be used with _entryPointsToCheck_ and _magicExtensions_.
Ideally package.json should use `"exports"` field documented in https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_package_entry_points. But not every one has updated to this new field yet.
259
+
_packagesManualOverrides_ is an object that can be used to override some of your dependencies package.json.
221
260
222
-
_packagesManualOverrides_ parameter is an object that can be used to override some of your dependencies package.json.
261
+
_packagesManualOverrides_ exists in case some of your dependencies use non standard fields to configure their entry points in their _package.json_. Ideally they should use `"exports"` field documented in https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_package_entry_points. But not every one has updated to this new field yet.
0 commit comments