node.js - Creating Node Package with Angular2 and Webpackage -


i building large application multiple projects want put angular2 components in module, gets shared between of modules.

since using webpack in projects nice use adavantages in node module, generated output not useable.

the reason why trying use webpack take advantage of loaders webpack provides. want seperate template , styles in different files.

is there way use webpack render angular2 components in way can use them node_module in different project?

by default webpack outputs bundle browser. if want code usable in project, can use output.library , output.librarytarget in webpack configuration. example:

output: {     library: 'mycomponentname', // component / library name     librarytarget: 'umd', // or 'commonjs2', 'var', ... } 

this result in bundle can import in browser or module system supports amd or commonjs2 (like webpack, browserify, requirejs, ...).

more information available in webpack documentation these 2 options.

bonus:

if not set output.library option, exported properties of main bundle exported. has effect bundlers/browsers not use amd or commonjs. example:

entrypoint.js:

module.exports = {     firstexport: 1,     secondexport: 2, }; 

with output.library set mylibrary, happen in browser:

var mylibrary = { firstexport: 1, secondexport: 2 }; 

without output.library, looks this:

var firstexport = 1; var secondexport = 2; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -