Project

General

Profile

1
/*
2
*   !!! ADD REAL API ADDRESSES BEFORE PRODUCTION !!!!
3
*/
4

    
5
var webpack = require('webpack');
6
var path = require('path');
7
var webpackMerge = require('webpack-merge');
8
const AotPlugin = require('@ngtools/webpack').AotPlugin;
9

    
10
// Webpack Config
11
var webpackConfig = {
12
  entry: {
13
    'main': './app/main.ts',
14
    'vendor': './app/vendors.ts',
15
    'polyfills': './app/polyfills.ts',
16
  },
17

    
18
  output: {
19
    publicPath: '/dist/',
20
    path: path.resolve(__dirname, './dist'),
21
  },
22

    
23
  plugins: [
24
    new webpack.ContextReplacementPlugin(
25
      // The (\\|\/) piece accounts for path separators in *nix and Windows
26
      /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
27
      path.resolve(__dirname, './'),
28
      {
29
        // your Angular Async Route paths relative to this root directory
30
      }
31
    ),
32
    new webpack.ProvidePlugin({
33
      jQuery: 'jquery',
34
      $: 'jquery',
35
      jquery: 'jquery'
36
    }),
37
    new webpack.optimize.CommonsChunkPlugin({
38
      name: ['app', 'vendor', 'polyfills']
39
    })
40
  ],
41

    
42
  module: {
43
    loaders: [
44
      {test: /\.css$/, loaders: ['to-string-loader', 'css-loader']},
45
      {test: /\.html$/, loader: 'raw-loader'},
46
      {test: /\.scss$/, loaders: ['style', 'css', 'postcss', 'sass']},
47
      {test: /\.(woff2?|ttf|eot|svg)$/, loader: 'url?limit=10000'},
48
      {test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery'}
49
    ]
50
  },
51

    
52
};
53

    
54

    
55
// Our Webpack Defaults
56
var defaultConfig = {
57
  devtool: 'source-map',
58

    
59
  output: {
60
    filename: '[name].bundle.js',
61
    sourceMapFilename: '[name].map',
62
    chunkFilename: '[id].chunk.js'
63
  },
64

    
65
  resolve: {
66
    extensions: ['.ts', '.js'],
67
    modules: [path.resolve(__dirname, 'node_modules')]
68
  },
69

    
70
  devServer: {
71
    historyApiFallback: true,
72
    watchOptions: {aggregateTimeout: 300, poll: 1000},
73
    headers: {
74
      "Access-Control-Allow-Origin": "*",
75
      "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
76
      "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
77
    },
78
    proxy: {
79
      '/uoa-repository-manager-service': {
80
        target: 'http://localhost:8480',
81
        secure: false
82
      }
83
    }
84
  },
85

    
86
  node: {
87
    global: true,
88
    crypto: 'empty',
89
    __dirname: true,
90
    __filename: true,
91
    process: true,
92
    Buffer: false,
93
    clearImmediate: false,
94
    setImmediate: false
95
  }
96
};
97

    
98

    
99
module.exports = function (env) {
100
  console.log(env);
101
  if ((typeof env == 'undefined') || (!env.release && env.release != true)) {
102
    webpackConfig.plugins.push(
103
      new webpack.DefinePlugin({
104
        "process.env": {
105
          PRODUCTION: JSON.stringify(false),
106
          API_ENDPOINT: JSON.stringify(process.env.API_ENDPOINT || "/uoa-repository-manager-service"),
107
          FAQ_ENDPOINT: JSON.stringify(process.env.FAQ_ENDPOINT || "https:/demo.openminted.eu/provide/api"),
108
          AAI_ENDPOINT: JSON.stringify(process.env.AAI_ENDPOINT || "/uoa-repository-manager-service/openid_connect_login"),
109
          FAQ_HOMEPAGE: JSON.stringify(process.env.FAQ_HOMEPAGE || "http://audrey.athenarc.gr:5555"),
110
          BASE_URL: JSON.stringify(process.env.BASE_URL || "http://localhost:4200")
111
        }
112
      })
113
    );
114
    webpackConfig.module.loaders.push(
115
      {
116
        test: /\.ts$/,
117
        loaders: [
118
          'awesome-typescript-loader',
119
          'angular2-template-loader',
120
          'angular2-router-loader'
121
        ]
122
      }
123
    );
124
  } else {
125

    
126
    webpackConfig.plugins.push(
127
      new AotPlugin({
128
        tsConfigPath: 'tsconfig.json',
129
        entryModule: path.resolve(__dirname, './app/app.module#AppModule')
130
      })
131
    );
132
    webpackConfig.plugins.push(
133
      new webpack.DefinePlugin({
134
        "process.env": {
135
          PRODUCTION: JSON.stringify(true),
136
          API_ENDPOINT: JSON.stringify("/uoa-repository-manager-service"),
137
          FAQ_ENDPOINT: JSON.stringify("http://audrey.athenarc.gr:5555/api"),
138
          AAI_ENDPOINT: JSON.stringify("/uoa-repository-manager-service/openid_connect_login"),
139
          FAQ_HOMEPAGE: JSON.stringify("http://audrey.athenarc.gr:5555"),
140
          BASE_URL: JSON.stringify("http://localhost:4200")
141
        }
142
      })
143
    );
144
    webpackConfig.module.loaders.push(
145
      {
146
        test: /\.ts$/,
147
        loaders: [
148
          '@ngtools/webpack'
149
        ]
150
      }
151
    );
152
  }
153
  return webpackMerge(defaultConfig, webpackConfig);
154
};
(11-11/11)