node.js - Wrap many internal modules for exporting in typescript -
i looking @ using typescript within node, , used using typescript via ///<reference.../>
syntax purely using internal modules. larger projects can unwieldy can have modules referencing other modules have interlinking references.
so node project thinking trying group logical components internal modules/classes before, internally reference each other, expose them via 1 external module expose underlying classes etc.
this way syntax similar of nodes existing requiring mechanisms, like:
import database = require("my-external-db-module.ts"); var connection = new database.connection(someurl);
rather than
///<reference path="my-internal-db-modules.ts" /> var connection = new database.connection(someurl);
and imagine syntax like:
///<reference path="all-my-internal-module-files-etc.ts" /> ///<reference path="..." /> export module someexposingmodule { // not quite sure put in here expose internal modules }
so there sort of best practices around sort of thing or others have done similar, or stick using internal modules complex stuff?
i not sure if bad practice or not here how solved problem.
first quick summary of problem again:
i have multiple files logically grouped under namespace, example framework
files under there framework.*
, such framework.database
or framework.unitofwork
. these compiled via tsc --out framework.js ...
of outputted framework.js
file.
now above sounds fine, not allow export modules when using --out because spans multiple files, node work need export modules somehow, appended typescript file manually me in compilation:
// exporter.ts module.exports = framework;
so providing last file added tsc
compilation end like:
// framework.js var framework; (function (framework) { // lots of stuff })(framework || (framework = {})); module.exports = framework;
so export internal modules fine , export declaration included because of exporter.ts file included.
so not sure if bad practice allows me have best of both worlds, re-usable module laid out namespaces , spread across sensible file structure, , compiled single module can included either references or nodejs require.
so usage like:
var framework = require("./framework"); var database = new framework.database.dbconnection();
Comments
Post a Comment