Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading of modules with main = path (./lib/) instead of main = path/file (./lib/index.js) #22

Closed
meaku opened this issue Sep 13, 2012 · 4 comments

Comments

@meaku
Copy link

meaku commented Sep 13, 2012

I had an issue today with bundling the validator node-module. I checked the package.json and the problem is how the main-file is referenced:

"main"          : "./lib",

I changed it locally to lib/index.js and it works.
I think it's valid to reference main via path instead of a full-file-path, so webpack should resolve it the same way node does it.

And for testing with the validator module: Bundling the validator module doesn't work completely because it's referencing the native node-module "net". It removed this dep and it works completely.

@sokra
Copy link
Member

sokra commented Sep 13, 2012

I'll fix it.

For the net dependency: You can offer a fake net module in the web_modules folder so validator find it.

For the validator module you may provide also a isIP method in the fake module.

// validator/lib/validators.js
// ...
    isIP: function(str) {
        // net.isIp requires node >= 0.3.0
        var modernNode = typeof net.isIP === 'function';
        var method = modernNode? validators.isIPNet : validators.isIPManual;
        return method(str);
    },
    isIPNet: function(str) {
        return net.isIP(str) !== 0;
    },
// ...

sokra added a commit to webpack/enhanced-resolve that referenced this issue Sep 13, 2012
@sokra sokra closed this as completed Sep 13, 2012
@sokra
Copy link
Member

sokra commented Sep 13, 2012

It should work now.

@meaku
Copy link
Author

meaku commented Sep 13, 2012

Awesome! That was fast ;)
When will you publish a new version to npm?

And for the web_module thing: I've sent a pull request for node-validator which removed the net-dependency. I was aware of the web_module way but fixing it at the module itself seemed to make more sense, because other people might want to use the module with webpack and browserify as well.

@sokra
Copy link
Member

sokra commented Sep 13, 2012

I've publish it already, but it wasn't a change to webpack but to a dependency of webpack enhanced-resolve. That module care about the resolving process.

Therefore webpack provides a syntax for module authors to provide different versions of node.js and webpack. xxx.js will be replaced with xxx.web.js or xxx.webpack.js.

validator could be organized this way:

// validators.js
var isIP = require("./isIP");
// isIP.js
module.exports = require("net").isIP;
// isIP.web.js
module.exports = function(str) {
 // add some browser replacement here
}

I proposed it for browserify here already: browserify/browserify#174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants