2

I have developed an Angular 2 application using npm, As a fresher,I don't know some ways like below. When I publish I used npm publish so that it publish the application in npm account in the web. So here, is there any way to publish our app in the localhost,because I don't want to use npm account and I just need to avoid node_modules folder on publishing ? If any other way,that can be used to publish the Angular2 Application in local other than npm, let me know.I try that.

If it is not possible to publish the application without npm web account, Kindly let me know please . Excuse mistakes,If any.Thanks in adv :)

Sridhar Paiya
  • 458
  • 2
  • 9
  • 27
  • 1
    could you be more specific ? angular2 apps can be run locally using `npm start`. i am not sure what are you trying to do when you say publish – Bhushan Gadekar Apr 28 '16 at 05:43
  • I want to avoid devdependency files(node_modules) when publishing,Its happening but my app is published on npm account, Then while I run the command `npm i myapp` It is intalling on localhost. Instead I want to publish directly in my localhost.Is there any way to do that ? by using Gulp or else ? If can't,no problem,Let me know. – Sridhar Paiya Apr 28 '16 at 05:54
  • @sridhar What exactly do you mean with "publish to localhost". What do you want to archive a publish? Be more specific, or we will not be able to help you, I'm sorry. – Dinistro Apr 28 '16 at 06:04

3 Answers3

6

npm publish is to make a library package available to other for free use.

That's not what you use for making a web application available. This is called deployment. For deployment you usually execute a build step that transpiles TS to JS, and combines them into a single file to reduce the number of requests the browser needs to make in order to get all source files of your application. It may also inline component HTML and CSS. This build step can also minify and mangle to JS code to reduce the resulting file size even more.

The resulting output can just be copied to any directory that any web server is able to serve to a browser either on your local machine or at some machine of a web hosting provider.

There are different ways to build your application depending on your setup.

See for example How to deploy Angular 2 application developed in Typescript to production?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I still have some doubts, I think there is an option to publish our app in private web server using npm, If it is so, How can I do that ? help me please – Sridhar Paiya Apr 28 '16 at 08:41
  • You can run your private npm repository to host library package but that doesn't serve your web applications, it just allows you to `npm install` a package from this server. If you want to run your web application you want to deploy it, not to publish. – Günter Zöchbauer Apr 28 '16 at 08:44
1

You need browserify, that's all

browsers need references to all js files to be put in the html, they don't understand node's require() method that forms modules dependencies

what browserify does is traversing the entire dependency graph of your project, recursively bundling up all the required modules starting at the given root into a single js file

install it by node package manager

npm install -g browserify

use it to bundle all needed modules staring at main.js

browserify main.js -o bundle.js

now put a single script tag into your html

<script src="bundle.js"></script>
Mohamed Ali
  • 3,717
  • 1
  • 33
  • 39
0

as far as i know, node_modules contains dependencies for typescript transpilers and few others. so it will not be possible to publish an app without using node_modules.

perhaps you can try using Plnkr or jsFiddle

where you can make imports online using cdn links for node_modules and publish your app.

it will be easy compared to other alternatives.

hope this helps.

Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131
  • I think node_modules files are devdependencies,not dependencies,right ? Devdependencies can be neglected after development.Some of the files like angular2.dev.js ,system.js are dependencies.so we require that even after publishing right?! – Sridhar Paiya Apr 28 '16 at 06:16