Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Angular2 project without using CLI

Tags:

angular

This is the Folder structure i have made for a project made in angular 2. I have deleted the Node-Module folder and other folder in order to fit it here. For styling i have only used Bootstrap. I have not used Angular-CLI. Can anyone guide me how should i deploy it ? Should i use gulp ? what should my steps be. I have gone through a lot of answers on stackoverflow but all were using GULP and CLI. Is it must to use both, if so please guide how to achieve deployment. Sadly there is nothing mentioned about deployment in Anular2 official website. Any help, guidance and suggestion is welcomed.

|--app
|   |-- logo.png
|   |-- components
|   |   |-- main.component.ts
|   |   |-- config.component.ts
|   |   |-- download-resources.component.ts
|   |   |-- header-footer.component.ts
|   |   |-- licence.component.ts
|   |   |-- menu-bar.component.ts
|   |   |-- process-status.component.ts
|   |   |-- release-history.component.ts
|   |   |-- upload-release.component.ts
|   |   `-- version.component.ts
|   |-- main
|   |   `--module.ts
|   |-- main.ts
|   |-- models
|   |   |-- config.model.ts
|   |   |-- meta-info.model.ts
|   |   |-- process-status.model.ts
|   |   `-- version.model.ts
|   |-- services
|   |   |-- cc-info.service.ts
|   |   |-- config.service.ts
|   |   |-- release-history.service.ts
|   |   |-- shared.service.ts
|   |   |-- upload-release.service.ts
|   |   `-- version.service.ts
|   `-- template
|       |-- download-resources.component.html
|       |-- licence.component.html
|       |-- license-info.component.html
|       |-- machines.component.html
|       |-- menu-bar.component.html
|       |-- process-status.component.html
|       |-- release-history.component.html
|       |-- topology-info.component.html
|       |-- topology-upload.template.html
|       |-- upload-release.component.html
|       `-- version.component.html
|-- index.html
|-- package.json
|-- styles.css
|-- systemjs.config.js
|-- tsconfig.json
`-- typings.json

This is my system.config.js file:

(function (global) {
  System.config({
    // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      tsconfig: true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },
    paths: {
      // paths serve as alias
      'npm:': 'node_module'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'main-app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

      // other libraries
      'ng2-file-upload' : 'npm:ng2-file-upload',
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
      'ts':                        'npm:[email protected]/lib/plugin.js',
      'typescript':                'npm:[email protected]/lib/typescript.js',

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.ts',
        defaultExtension: 'ts'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      'ng2-file-upload':{
        main: 'ng2-file-upload.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);
like image 414
heman123 Avatar asked Oct 28 '16 09:10

heman123


People also ask

Can I use Angular without CLI?

We will start by setting up the module loader, then use npm to install Angular and its dependencies, as well as some tools and polyfills we will need, such as the TypeScript compiler. Finally, we will create a minimal application skeleton, and write the code for bootstrapping it.

Can we install Angular CLI without npm?

Installing Angular CLI on Windows First, you need to have Node and npm installed on your development machine. There are many ways to do that, such as: using NVM (Node Version Manager) for installing and working with multiple versions of node in your system. using the official package manager of your operating system.

How is Angular application deployed?

Basic deployment to a remote serverlink For the simplest deployment, create a production build and copy the output directory to a web server. Copy everything within the output folder ( dist/project-name/ by default) to a folder on the server. Configure the server to redirect requests for missing files to index. html .


1 Answers

I solved this problem by using webpack. My webpack makes a bundle.js which includes all the .js .ts .html files and converts it into bundle.js. which i import in Index.html. This bundle.js contains all the things required for it to run. Other things required by my site, like style.css and some bootstrap libraries have to be included externally in index.html. Steps that you need to follow are:

  1. Include "compression-webpack-plugin": "^0.3.2" package in package.json in dev-dependency
  2. There are few more things to keep in mind when you use webpack. You need to use correct syntax to import your templates in componenet and there are few changes in routes.
  3. I have changed my build script as well in package.json. Added code for webpack to work

    "build": "npm run tsc && npm run clean && mkdir _dist && webpack --devtool inline-source-map",

  4. You need to configure your webpack. webpack.config.js contains all the configuration that i have done, It looks something like this.

var webpack = require("webpack");
var CompressionPlugin = require("compression-webpack-plugin");  
module.exports = {
entry: {
 "app": "./app/main"
 },
        output: {
            path: __dirname,
            filename: "./_dist/bundle.js",
            publicPath: 'http://localhost:4242/app'
        },
 resolve: {
        extensions: ['', '.js', '.ts', '.html']
    },
    devtool: 'source-map',
    module: {
        loaders: [
            {
  test: /\.ts$/,
                loaders: ['awesome-typescript-loader', 'angular2-template-loader']
            },
            {
                test: /\.html$/,
                loader: 'html'
            }
    ]
},
htmlLoader: {
    minimize: false
},
plugins: [
    new webpack.NoErrorsPlugin(),
],
devServer: {
    historyApiFallback: true,
 stats: 'minimal',
        inline: true,
        port: 4242
    }
}
like image 56
heman123 Avatar answered Nov 09 '22 07:11

heman123