Skip to content

Support 'paths' option #140

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

Open
Danetag opened this issue Sep 16, 2015 · 13 comments
Open

Support 'paths' option #140

Danetag opened this issue Sep 16, 2015 · 13 comments

Comments

@Danetag
Copy link

Danetag commented Sep 16, 2015

I probably do something wrong, but I'm building a webpack application (classic CommonJS app), and documentationjs seems to stop at the main.js without resolving the required modules.

'use strict';

var App      = require('app/app');

/**
 * Main module - App entry point
 * @module Main
 */

var Main = function(){};



/**
 * Callback fired once the document is ready
 * @public
 */
Main.prototype.onReady = function() {
  var app = new App();
  app.init();
}


var main = module.exports = new Main();

What do I do wrong? Thanks!

@tmcw
Copy link
Member

tmcw commented Sep 16, 2015

var App = require('app/app');

So app is an external module? I would expect this to be require('./app/app') if it was a local dependency.

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

Wow it totally worked...Thanks! There's no work around except "./"? Seems overkill as the require system works perfectly without :(

@tmcw
Copy link
Member

tmcw commented Sep 16, 2015

That part of the system is derived from browserify, and browserify rejects this input: if a require statement doesn't begin with ./, then it does not consider it internal. Oddly enough node accepts this input but there aren't any issues in browserify about this.

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

Hmm, I just switched the app from a browserify app to a webpack one, and browserify compiled it well before.. Hmm. Anyway, thanks for the tips!

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

I actually give to webpack/browserify an array of entry paths for the module definitions, array that documentjs doesn't have :( There's no way to specify such a thing?

@tmcw
Copy link
Member

tmcw commented Sep 16, 2015

Could you be a little clearer? What option do you use in particular with browserify/webpack? Documentation.js supports multiple entry points as multiple args to the binary or as an array to the API level.

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

Sorry! Here's the webpack config I'm using

module.exports = {
    entry: "./app/scripts/project/main.js",
    output: {
        path: __dirname,
        filename: "../app/js/bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" },
            { test: /\.html$/, loader: "handlebars-loader" }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.json', '.css'],
        modulesDirectories: ["app/scripts/project", "app/scripts/project/app", "node_modules", "tpl"]
    },
    resolveLoader: {
        fallback: path.join(__dirname, 'node_modules'),
        alias: {
          'hbs': 'handlebars-loader'
        }
    },
    node: {
        fs: "empty" // avoids error messages 
    }
};

I'm using gulp on top of it (so gulp-documentation as well)

@tmcw
Copy link
Member

tmcw commented Sep 16, 2015

Is there an equivalent option in browserify? I'm a little hesitant to pursue webpack-isms, since they deviate pretty far from what CommonJS & node do.

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

Sure!


  var b = browserify({ 
      cache: {},
      packageCache: {},
      fullPaths: true,
      extensions: ['.html'], 
      paths: ["app/scripts/project", "app/scripts/project/app", "node_modules", "tpl"],
      debug: true
  });

@tmcw tmcw changed the title Doesn't go through the module dependency Support 'paths' option Sep 16, 2015
@tmcw
Copy link
Member

tmcw commented Sep 16, 2015

👍 thanks, looks like we can pass a paths option into resolve.

@Danetag
Copy link
Author

Danetag commented Sep 16, 2015

Would be awesome!

@fgarcia
Copy link

fgarcia commented Aug 24, 2016

just one small wish since it has not being mentioned, resolving paths from NODE_PATH would be great

@richard-uk1
Copy link

+1 for resolving from NODE_PATH, this would allow me to bypass my multiple roots in webpack by just including those folders in my NODE_PATH. I believe module-deps already does this (from https://github.com/substack/module-deps)

opts.paths - array of global paths to search. Defaults to splitting on ':' in process.env.NODE_PATH

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

No branches or pull requests

4 participants