mikach / requirejs-babel

An AMD loader plugin for Babel
117 stars 32 forks source link

Do not append the .js extension to module names twice #39

Open prantlf opened 2 years ago

prantlf commented 2 years ago

Paths relative to the current directory include the file extension. But the recognition is not easy, because the name parameter passed to the plugin is not the original module name from the source code. For example:

import from 'src/sum'  ==> the plugin gets 'src/sum'
import from './sum'    ==> the plugin gets 'src/sum'
import from './sum.js' ==> the plugin gets 'src/sum.js'

RequireJS does not allow appending .js to module names from not relative paths. However, when writing a plugin, the ./ is not passed to it. As a workaround, I check if the name does not end with .js. Not the ultimate fix, but works probably well enough.