Comments (2)
As a workaround, I wrote my own extension. I post it here so that you understand the logic I meant:
{
resolveId (file, origin) {
if (file.charAt(0) === '/') {
return file
} else if (file.charAt(0) === '.') {
const basePath = path.dirname(origin)
return fileExists(path.join(basePath, file))
|| fileExists(path.join(basePath, file + '.js'))
} else {
return fileExists(path.join(__dirname, 'src', file))
|| fileExists(path.join(__dirname, 'src', file + '.js'))
|| fileExists(path.join(__dirname, 'src', file, 'index.js'))
}
function fileExists (file) {
try {
let stat = fs.statSync(file);
return stat.isFile() && file || null;
} catch (e) {
return null;
}
}
}
}
my options for includepaths
would be as follows
includepaths({
external: [],
paths: [ 'src' ],
relativeStrict: true,
extensions: [ '.js', '.json', '.html' ]
}),
from rollup-plugin-includepaths.
I've been thinking about this issue and it seems a bit complicated to cover all cases.
What if you have both cases in the same project? e.g a file called events.js
in the root folder (src) and another file trying to use the builtin events
module. If both use the same import name ('events'), is impossible to determine which is which.
If you prepend the file with a slash ('/events') that would in turn shadow imports with an absolute path if the logic changes.
If you only resolve files starting with ./ or ../, you have to "hardcode" the entire path to "events.js" somehow.
Correct me if I'm wrong, but this confusion is caused by a "sloppiness" in the way Node.JS resolves the file paths.
ES6 module syntax should always include the file extension in the module path ("events.js"). I'm not sure if that resolves all cases, but I think in your case you should use the file extension to differentiate between a file import ('events.js') and a builtin module import ('events'), rather than changing the resolution logic.
What do you think?
from rollup-plugin-includepaths.
Related Issues (18)
- Resolve `<module-name>/index.js` HOT 4
- Doesn't seem to work with module marked as external HOT 4
- Usage with `commonjs` & `node-resolve`? HOT 2
- does not load module index with other extensions HOT 2
- question: How to make it work with eslint? HOT 1
- "external" option doesnโt accept function as value HOT 1
- Breaking changes in updates 0.1.x HOT 1
- Resolve against package.json main field
- Unable to resolve file path? HOT 1
- External option is overrided by the plugin if it is a function HOT 2
- Any interest in supporting TypeScript at some point? HOT 1
- Smart resolve or wildcards HOT 1
- `resolveCachedPath` ignores `origin` HOT 5
- 0.1.4 caused `TypeError: rollupIncludePaths is not a function` on Ubuntu 16.04 HOT 2
- diamond import/export structure fails
- Not working with rollup-plugin-node-builtins HOT 7
- "filepath" does not exist in the hypothetical file system! #772 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rollup-plugin-includepaths.