dot-build / rollup-plugin-includepaths Goto Github PK
View Code? Open in Web Editor NEWRollup plugin to allow relative include paths in project files
Rollup plugin to allow relative include paths in project files
As i understand it, the resolve mechanism is as follows:
I would like to add a "strict" mode so that the first strategy only applies to path starting with either /
, ./
or ../
.
I currently have a problem with file names (e.g. events) conflicting with node modules, causing A module cannot import itself
errors.
Hi, there is any option to support module resolve, with multiple files. For example
...
include:{
'ramda': './node_modules/ramda/es'
}
...
I can use ramda/lens
or ramda/lensPath
Another option, should be, wildcards.
...
include:{
'ramda/**/*': './node_modules/ramda/es/**/*'
}
...
At the moment need to map each file separately.
...
include:{
'ramda/lens': './node_modules/ramda/es/lens',
'ramda/lensPath': './node_modules/ramda/es/lensPath'
...
}
...
This is quite time consuming, if you need import many modules from same location. I tried with path option, no success.
in function searchProjectModule, we only got:
newPath = this.resolvePath(path.resolve(workingDir, includePath[i], file, 'index.js'), false);
if (newPath) return newPath;
We should have this dynamic with the extensions that are set by the user in plugin.
In my case i also needed:
newPath = this.resolvePath(path.resolve(workingDir, includePath[i], file, 'index.jsx'), false);
if (newPath) return newPath;
I sugest the code like this:
// #1 - also check for 'path/to/file' + 'index.[file extension]'
for (let j = 0, jj = this.extensions.length; j < jj ; j++) {
newPath = this.resolvePath(path.resolve(workingDir, includePath[i], file, 'index'+this.extensions[j]), false);
if (newPath) return newPath;
}
thank you
So I was under the impression that doing
import {foo} from 'foo'
with
include: {foo: 'node_modules/foo.js' }
would use the file under node_modules as the import "base".
Instead I always get "Treating 'foo' as external dependency" and it never gets included. Is this expected?
It seems like external
option doesn’t accept or resolve Rollup external
option as function, it only accepts it as array of strings. Is this by design?
I'm not sure if this is a core rollup issue or with this plugin. I saw it after adding a common package index.js
Given
flow.js
/m/index.js
/m/a.js
/m/b.js
/m/common.js
flow imports ./m
a imports ./common
b imports ./common
common has no imports
When I refer to a common export in the index file it cannot find it as it doesn't have the $1 postfix.
If i want to flag as external all modules that are not in the src directory whith this rollup configuration file :
import includePaths from "rollup-plugin-includepaths";
export default {
entry: "main.js",
format: "cjs",
plugins: [
includePaths({
paths: ["src"]
})
],
external: id => !(/src\//.test(id)),
dest: "dist/bundle.js"
};
then the external function is not used, it is replaced by the externalModules
array
I´m happily using the plugin version 0.1.2, like
var includePaths = require('rollup-plugin-includepaths');
rollup({
format: "iife",
...
plugins: [
includePaths({ /** options */ })
]
})
but the version 0.1.7 with the same usage returns:
TypeError: includePaths is not a function
I have already tried to turn it off and on again but no luck...
I have multiple imports like this:
import react from 'react'; // <-- node_modules
import somethingLocal from 'some/placeLocal'; // <-- relative to ./src/
Using rollup-plugin-includepaths
works well on its own, but I also want to include external dependencies in node_modules in my bundle. Using alongside commonjs and node-resolve causes errors like:
Could not resolve 'shared/store'
i.e. it can't differentiate between global mods, and what I've specified as being local.
Usage instructions in the readme would be a big help, thanks.
Currently index
is only attempted to be resolved for relative file paths, not for paths beginning in the source directory.
https://github.com/dot-build/rollup-plugin-includepaths/blob/master/src/plugin.js#L189
I was able to solve this temporarily by adding \/index.js
as an extension like so:
function makePlugin(path) {
var includePathOptions = {
include: {},
paths: [path],
external: [],
extensions: ['.js', '.json', '\/index.js']
};
return includePaths(includePathOptions);
}
This is the original issue, but I'm copying its content here:
Hello, I have made a little app in order to test rollup with babel, but I can't import modules.
I get this message: "filepath" does not exist in the hypothetical file system!
but "filepath" does exist.
This is my gulpfile.js
let gulp = require('gulp'),
runSequence = require('run-sequence'),
rollup = require('gulp-rollup'),
rollupIncludePaths = require('rollup-plugin-includepaths'),
babel = require('rollup-plugin-babel');
gulp.task('default', () => {
const includePathOptions = {
paths: ['src']
};
return gulp.src('src/app.js')
.pipe(rollup({
entry: './src/app.js',
sourceMap: 'inline',
plugins: [
rollupIncludePaths(includePathOptions),
babel({
presets: ['es2015-rollup'],
babelrc: false
})
],
format: 'umd',
moduleName: 'testing'
}))
.pipe(gulp.dest('dist'));
});
What am I missing?
Thank you.
I was doing some TypeScript a few weeks back and noticed my .ts
files would have a .js
appended to them.
https://github.com/dot-build/rollup-plugin-includepaths/blob/master/src/plugin.es5.js#L145
Is legit TypeScript support a thing anyone else might be interested in or no?
Currently resolveCachedPath
looks like this:
if (id in this.cache) {
return this.cache[id];
}
return false;
So in this situation:
// directory-a/script.js
import value from './value';
export default value;
// directory-b/script.js
import value from './value';
export default value;
the value
will be incorrect in one case, because exactly one of directory-a/value.js
and directory-b/value.js
will be cached (as ./value.js
). That is why the origin also has to be taken into consideration.
@darlanalves I'm currently looking into this, do you see a chance to get this out quickly after it is patched?
Looks like this plugin don't work well in company with rollup-plugin-node-builtins
.
My goal is to use IO-free modules like node std path
in my bundle. This works ok if includepaths is disabled. However, when I enable it I got error No name was provided for external module 'path' in options.globals – guessing 'path'
. I've tried to rearrange my plugins, move includepaths down or up. I've also tried to use external: [ 'path' ]
option, but it didn't work for me. I got the same error no matter the config state.
Is it possible to make them work together or I just missing something and includepaths
isn't meant to work in such case? Will glad any help or tips.
I'm using the es5 version, requiring it like this, var rollupIncludePaths = require('rollup-plugin-includepaths');
.
when I downgrade to 0.1.2, it works fine.
My current folder scructure:
.
├── package.json
├── rollup.config.js
├── public
├── source
│ ├── scripts
│ │ └── index.js
│ │ └── utils
│ │ └── select.js
My rollup.config.js
:
import resolve from 'rollup-plugin-node-resolve';
import cjs from 'rollup-plugin-commonjs';
import es6 from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import paths from 'rollup-plugin-includepaths';
const plugins = [
paths({
include: {
select: 'source/scripts/utils/select.js'
}
}),
resolve({
main: true,
browser: true
}),
cjs(),
es6()
];
export default {
entry: 'source/scripts/index.js',
dest: 'public/bundle.js',
format: 'iife',
plugins
};
When I try to reference the alias for my module:
/* some-file.js */
import select from 'select';
I get this error:
Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at RollupIncludePaths.searchProjectModule (/Users/rafaelrinaldi/work/project/node_modules/rollup-plugin-includepaths/src/plugin.es5.js:191:45)
at RollupIncludePaths.searchModule (/Users/rafaelrinaldi/work/project/node_modules/rollup-plugin-includepaths/src/plugin.es5.js:164:73)
at RollupIncludePaths.resolveId (/Users/rafaelrinaldi/work/project/node_modules/rollup-plugin-includepaths/src/plugin.es5.js:89:55)
at resolveId (/Users/rafaelrinaldi/work/project/node_modules/rollup-plugin-includepaths/src/plugin.es5.js:301:29)
at /Users/rafaelrinaldi/work/project/node_modules/rollup/www/ROLLUP/rollup/src/utils/first.js:10:31
at tryCatch (/Users/rafaelrinaldi/work/project/node_modules/rollup/www/ROLLUP/rollup/node_modules/es6-promise/lib/es6-promise/-internal.js:185:12)
at invokeCallback (/Users/rafaelrinaldi/work/project/node_modules/rollup/www/ROLLUP/rollup/node_modules/es6-promise/lib/es6-promise/-internal.js:197:13)
at publish (/Users/rafaelrinaldi/work/project/node_modules/rollup/www/ROLLUP/rollup/node_modules/es6-promise/lib/es6-promise/-internal.js:168:7)
at flush (/Users/rafaelrinaldi/work/project/node_modules/rollup/www/ROLLUP/rollup/node_modules/es6-promise/lib/es6-promise/asap.js:87:5)
at _combinedTickCallback (node.js:370:9)
Environment settings:
~/work/project master*
❯ npm -v
3.8.2
~/work/project master*
❯ node -v
v5.8.0
~/work/project master*
❯ cat package.json | ag includepaths
"rollup-plugin-includepaths": "^0.1.1",
From the stack trace it seems to be Rollup not finding the path for select.js
which therefore seems to be a bug on the path resolution of this plugin.
Am I doing something wrong?
Thanks.
I would like includepaths to resolve into a non-standard node_modules location for external entries. This sort of works, if the node_modules path is listed in the paths option. However, it only works for packages that have an index.js as their entry point. Many packages use different entry points as described in the main field of their package.json file. This request is then to resolve packages against their main field if a package.json exists.
A note as well that the package.json main field should resolve before just appending a index.js
to the file name.
I mean this rule: import/no-extraneous-dependencies
for example if I have the following project structure:
▾ src/
index.js
InputStream.js
TokenStream.js
▾ test/
TokenStream_test.js
and then in my test/TokenStream_test.js
I have this import:
import TokenStream from 'TokenStream';
which results in error:
'TokenStream' should be listed in the project's dependencies. Run 'npm i -S TokenStream' to add it (import/no-extraneous-dependencies) [javascript/eslint]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.