PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

Many devDependencies are part of build process, these should be moved to dependencies

Open paynoattn opened this issue 10 years ago • 11 comments

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

  • I'm submitting a ... [x] bug report [x] feature request [x] question about the decisions made in the repository
  • Do you want to request a feature or report a bug? Bug
  • What is the current behavior? Currently when node is in production mode on certain remote servers such as heroku, devDependencies are not installed. Therefore, many of these dependencies should be moved to the dependencies list.
  • What is the expected behavior? Application should deploy without 'module "webpack" not found' messages in production environments.
  • What is the motivation / use case for changing the behavior? Your app should work in production.
  • Please tell us about your environment:
  • Angular version: 2.0.0-rc1
  • Browser: N/A

I have already fixed this here. I can create a pull request if this is approved.

paynoattn avatar May 20 '16 00:05 paynoattn

I also removed dependencies not being used anywhere in the code, such as style-loader and several others. I can moved this into a seperate issue.

paynoattn avatar May 20 '16 01:05 paynoattn

Somebody correct me if I'm wrong, but this is the attended behavior, you're supposed to build your code on your dev machine and only deploy the built version (So no need for those dependencies).

yann-stepienik-cko avatar May 24 '16 09:05 yann-stepienik-cko

Sorry I'm new to this package so I'm not sure what the intention should be since it's not spelled out, I assumed that this package was meant for deployment automation, given many of the of the scripts steps in package.json such as postinstall and build:prod and server:prod.

IMHO the idea of 'build on your dev machine and only deploy the built version' is not good practice. The only way to deploy then is either use ftp/scp or something similar, or commit your dist/ directory. I don't like either of those options.

In a node production environment everything could be automated by moving these dependencies, using git to checkout your latest code in production, and running your build and either npm run server:prod or adding a server.js and creating a simple express app that serves your dist folder.

paynoattn avatar May 24 '16 12:05 paynoattn

On my side the deployment is still automated, I call the deployment, it builds everything and cause the upload via SSH of the dist/ resulted (and remotely call npm install). I think deployment is much lighter that way (which makes sense for production) as you move only a bunch of files instead of your whole source code (that is not going to be used anyway after the build) also, you cut global dependencies like Typescript. You might as well not want your original source code to be uploaded to a production server. Another argument would be that building your source code on the target server will make it busy for a much higher time, and will totally break things if the build fail (meanwhile if your local build fail, nothing gets uploaded).

yann-stepienik-cko avatar May 24 '16 12:05 yann-stepienik-cko

I see your point about build failure but you're making a lot of assumptions about your ng2 app and your production environment. There are a number of use cases where you would want or need to build in production, such as if you are trying to integrate your ng2 app with a node app, or that the security team for your company has disabled ssh traffic in the network, or any other number of reasons.

We could argue all day which use case is more important/popular but since my changes don't effect your ability to deploy your way at all and gives others such as me the ability to build in production it seems kind of an irrelevant argument to have for me.

The purpose of a starter is to help as many use cases as possible, not just yours. :D

paynoattn avatar May 24 '16 19:05 paynoattn

I don't get your point @paynoattn, why in any way would you like to install 'building' dependencies in a production environment? Building is a oneshot action, and the libraries would remains useless after it.

If you would like to build on production environment:

npm install
#Build your app
rm -rf ./node_modules
npm install --production

anthonyraymond avatar May 31 '16 12:05 anthonyraymond

I don't get your point. If the intention is to not have unused build code in production then having dependencies seperated by devDependencies make no sense because none of this repository's node_modules will be used post-build, you should just remove your node_modules directory.

The point here is that if you want to build in production, via something like heroku, without having to do a manual deploy through the command line passing flags.

paynoattn avatar May 31 '16 15:05 paynoattn

@paynoattn if you don't want to do a "manual deploy" then add an npm task to do it.

seiyria avatar Jan 24 '17 20:01 seiyria

The devDependencies are exactly how they need to be. You don't deploy development builds to a production server. i.e there is no need for webpack to be in a deployment nor any of it's loaders.

It's JavaScript, which is served as static assets with something like nginx or using angular universal rendered on the server.

joshwiens avatar Jan 24 '17 20:01 joshwiens

If you want heroku to build the production site and serve it you can try the following in package.json.

    "heroku-prebuild": "npm install --dev",
    "heroku-postbuild": "npm run build:prod"
    "start": "npm run server:prod",

fer662 avatar Mar 16 '17 14:03 fer662

Just giving my opinion here because my build is failing as well

Personally I deploy using Flynn, that is based on buildpack, like Heroku. And I think that it does not make sense that npm run build:prod fails after doing npm install --only=production. The dependencies needed to build production assets should be included in the production dependencies.

seza443 avatar Apr 24 '17 10:04 seza443