Node.js loader for import specifiers as file paths without extensions or as directory paths
Install:
npm i extensionless
Start node
with the following flag added:
--experimental-loader=extensionless
You can now use import specifiers as file paths without extensions or as directory paths:
import mod from './mod'
import mod from './mod' assert {type: 'json'}
If the specifier ends with a path separator, it only looks for index files in that directory:
import mod from '../mod/'
import mod from '../mod/' assert {type: 'json'}
To configure this package, you can add the field extensionless
to package.json
:
"extensionless": {
"lookFor": ["js", "mjs", "cjs"]
}
Field | Default Value |
---|
lookFor | ["js"] |