requirejs - Absolute path for almond when using require.js optimize -
i'm trying code optimize single file using apparently non-standard setup , i'm struggling understand different paths mean.
imagine i'm making variant of r
the requirejs command-line tool includes almond. want able wrap almond using almond included tool.
my directory structure
someappfolder | +--main.js
in related folder
myrplusalmondbuilder | +--myrplusalmonbuilder.js | +--node_modules | +--almond | | | +--almond.js | +--requirejs | ...
so, want myrplusalmondbuilder
able build single js bundle main.js
this
cd myrplusalmondbuilder node myrplusalmondbuilder.js someappfolder/main.js
here's simple myrplusalmondbuilder.js
var requirejs = require('requirejs'); var path = require('path'); var filename = process.argv[2]; var dirname = path.dirname(filename); var barename = path.basename(filename, ".js"); var config = { baseurl: dirname, name: "node_modules/almond/almond", include: barename, insertrequire: [barename], out: "out.js", wrap: true, }; // show values console.log(json.stringify(config, undefined, " ")); requirejs.optimize(config, function() { console.log("result in:", config.out); }, function(err) { console.error(err); });
calling this
cd myrplusalmondbuilder.js node myrplusalmondbuilder.js /users/gregg/temp/delme-requirejs/someappfolder/main.js
but get
{ "baseurl": "/users/gregg/temp/delme-requirejs/someappfolder", "name": "node_modules/almond/almond", "include": "main", "insertrequire": [ "main" ], "out": "out.js", "wrap": true } { [error: error: error: module path not exist: /users/gregg/temp/delme-requirejs/someappfolder/node_modules/almond/almond.js module named: node_modules/almond/almond. path relative to: /users/gregg/temp/delme-requirejs/myrplusalmondbuilder
trying these other values name
fail
// dot in front name: "./node_modules/almond/almond", // .js on end name: "node_modules/almond/almond.js", // .dot in front , .js on end name: "./node_modules/almond/almond.js", // absolute path almond.js .js name: path.join(__dirname, "node_modules/almond/almond.js"), // absolute path almond.js without .js name: path.join(__dirname, "node_modules/almond/almond"),
the ones ".js" get
[error: error: enoent, no such file or directory '/users/gregg/temp/delme-requirejs/someappfolder/node_modules/almond/almond.js' @ error (native) ]
the ones full path get
[error: error: enoent, no such file or directory '/users/gregg/temp/delme-requirejs/someappfolder//users/gregg/temp/delme-requirejs/myrplusalmondbuilder/node_modules/almond/almond.js' @ error (native) ]
using relative path main.js almond works
name: path.relative(dirname, path.join(__dirname, "node_modules/almond/almond.js")),
but won't work in windows if tool in in c:/somefolder/myrplusalmond
, file in in d:/someappfolder/main.js
is there way use absolute paths almond?
i found 1 way add path almond
var config = { baseurl: dirname, name: "__dontclash_almond__/almond", include: barename, insertrequire: [barename], out: "out.js", wrap: true, paths: { __dontclash_almond__: path.join(__dirname, "node_modules/almond"), }. };
seems kind of hacky because have hope don't clash user chosen name. of course it's unlikely clash
Comments
Post a Comment