Comments (8)
Hey @mk-pmb,
There are two possible solutions.
If all of your .json files are in one directory, you can configure a package for that directory and use a curl plugin as a curl loader. Here's the basic information for creating a package: https://github.com/cujojs/curl#package-support To configure a curl loader for a package, see here: https://github.com/cujojs/curl/tree/master/src/curl/loader (last example is very close to what you want, just replace the link
plugin with the json
plugin.
If you have .json files mixed with normal modules, you can try the experimental "ext" plugin. It's here: 6859c8c Copy that module and put it somewhere within your project. It looks like it should Just Workβ’, but it hasn't been tested on recent versions of curl.js, afaict.
You can use the package configuration (as above) to specify the loader, or you can specify it for the entire app by specifying a loader: 'path/to/ext.js'
at the top-level config.
Let us know if either of these works! :)
-- John
from curl.
I just noticed that you asked about a general solution. Yes, you can use the experimental ext loader as an example.
The ext loader probably shows you what you need to know. There are other loaders with more complex needs, here, too: https://github.com/cujojs/curl/tree/master/src/curl/loader (look at the source code for docs).
from curl.
If all of your .json files are in one directory,
Nope, that would've been too easy. :-)
you can try the experimental "ext" plugin
Thanks! Looks like what I need, I'll try it asap. (Edit: The ext loader is currently also available as a branch)
from curl.
So my loader gets a require
function as one of its arguments. Is that one guaranteed to avoid loops? I couldn't find that guarantee in the docs.
Assume I find a way to configure my nio
(node inter-op) plugin to be used for everything, or at least for the "package" that is all of my node_modules/
, thus includes curl-amd
and nio
.
Then nio
decides that mystery.mys
is for the mystery
plugin, and forwards it with require('mystery!' + resourceId, β¦)
, mystery
knows a filename with exactly 3 y
s must be AMD-style JS and thus forwards it without any prefix. (Worked before nio
because .mys
was configured as a dontAddFileExt
.) Will curl give that resourceId to nio
again?
PS: In case there is no guarantee: Is there a mechanism to specify that a resourceId is final, no plugins shall be applied? Maybe !
as first character of the resourceId?
from curl.
Hmmmm... yah. There is a circle. Bummer.
If you can stipulate that your loader will only be configured for packages that contain node modules, then you could prepend the "json!" prefix to .json files and prepend "cjsm11!" to node files. (See the cjsm11 loader/plugin.) This will ensure that a different loader/plugin will be used for the recursive require
.
If the above isn't feasible, it's also possible to override curl's internal API. See here for an example of overriding the define
function and here for an example of overriding the require
function (which is different for each module).
from curl.
Thanks! π I'll try and hack a custom require then. Nevertheless I think an official and easy way to bypass plugins would be nice, so I requested #299 .
from curl.
So I've adapted the dojo shim require code
define(/*β¦*/ ['curl/_privileged'], function (priv) { /*β¦*/
origCreateContext = priv['core'].createContext;
var core = require('curl/_privileged').core;
console.log('internode init:', {
version: require('curl').version, // "0.8.13"
core: String(core), // "[object Object]"
origCC: String(core.createContext), // "undefined"
});
which seems to indicates that I managed to reach the core but there's no .createContext
function in it. What did I miss?
Update 1: Seems to be about minification. I dumped the core object's keys and they were A, j, M, ea, na, T, ma, U, $, b, s, Z, B, m, S, la, ga, N, F, ja, ia, oa, ka, ha, ba, o
.
So I'll probably have to build my own curl in order to monkey-patch it, or is cC exported somewhere else with a better name?
If not, could you ship a non-minified alias for it in the default kitchen-sink build? In that one, people won't mind the few bytes given what feature they get. ;-)
Update 2: Looking for where to add the aliases, I found that .createContext
won't be the only problem, because probably the .require
is minified as well. Also toUrl
and toAbsId
sound good for monkey-patching as well, would you mind exporting them too?
from curl.
Thanks for suggesting SystemJS over in #271. It has all the plugin guessing that I currently need, so for now I won't pursue my curl approach.
Curl is great nonetheless, it helped me a lot in the past few years. Excellent work!
from curl.
Related Issues (20)
- curl-css shouldn't wait for readystate == 'complete' HOT 7
- What if the module is a function? HOT 1
- Similar functionality of curl with require.js map config? HOT 1
- Using domReady! as a dependency argument causes an error HOT 4
- dealing with the window object HOT 7
- Unhandled error is eaten by curl when bootstrap code has a json plugin dependency HOT 5
- For anyone facing the error : Multiple anonymous defines encountered HOT 1
- Multiple bundles HOT 17
- Remove old IE event listeners in domReady HOT 1
- License for curl HOT 4
- "undefined" from import when define function throws an exception HOT 8
- Modules "undefined" when error occurs HOT 1
- "new Promise()" syntax non-standard? HOT 1
- Promise.then doesn't wait HOT 5
- Add build with js plugin
- multiple anonymous defines HOT 2
- Feature Request: Add syntax to bypass plugins
- cjsm11 loader hides a TypeError and falsely reports success
- ε¦δΉ 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 curl.