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
  },
79

    
80
  node: {
81
    global: true,
82
    crypto: 'empty',
83
    __dirname: true,
84
    __filename: true,
85
    process: true,
86
    Buffer: false,
87
    clearImmediate: false,
88
    setImmediate: false
89
  }
90
};
91

    
92

    
93
module.exports = function (env) {
94
  console.log(env);
95
  if ((typeof env == 'undefined') || (!env.release && env.release != true)) {
96
    webpackConfig.plugins.push(
97
      new webpack.DefinePlugin({
98
        "process.env": {
99
          PRODUCTION: JSON.stringify(false),
100
          API_ENDPOINT: JSON.stringify(process.env.API_ENDPOINT || "http://aleka.athenarc.gr:8380/repomanager-service-dev"),
101
          FAQ_ENDPOINT: JSON.stringify(process.env.FAQ_ENDPOINT || "http://audrey.athenarc.gr:5555/api"),
102
          AAI_ENDPOINT: JSON.stringify(process.env.AAI_ENDPOINT || "http://aleka.athenarc.gr:8380/repomanager-service-dev/openid_connect_login"),
103
          FAQ_HOMEPAGE: JSON.stringify(process.env.FAQ_HOMEPAGE || "http://audrey.athenarc.gr:5555"),
104
          BASE_URL: JSON.stringify(process.env.FAQ_HOMEPAGE || "http://aleka.athenarc.gr:3000")
105
        }
106
      })
107
    );
108
    webpackConfig.module.loaders.push(
109
      {
110
        test: /\.ts$/,
111
        loaders: [
112
          'awesome-typescript-loader',
113
          'angular2-template-loader',
114
          'angular2-router-loader'
115
        ]
116
      }
117
    );
118
  } else {
119
    webpackConfig.plugins.push(
120
      new AotPlugin({
121
        tsConfigPath: 'tsconfig.json',
122
        entryModule: path.resolve(__dirname, './app/app.module#AppModule')
123
      })
124
    );
125
    webpackConfig.plugins.push(
126
      new webpack.DefinePlugin({
127
        "process.env": {
128
          PRODUCTION: JSON.stringify(true),
129
          API_ENDPOINT: JSON.stringify("http://aleka.athenarc.gr:8380/repomanager-service-dev"),
130
          FAQ_ENDPOINT: JSON.stringify("http://audrey.athenarc.gr:5555/api"),
131
          AAI_ENDPOINT: JSON.stringify("http://aleka.athenarc.gr:8380/repomanager-service-dev/openid_connect_login"),
132
          FAQ_HOMEPAGE: JSON.stringify("http://audrey.athenarc.gr:5555"),
133
          BASE_URL: JSON.stringify("http://aleka.athenarc.gr:3000")
134
        }
135
      })
136
    );
137
    webpackConfig.module.loaders.push(
138
      {
139
        test: /\.ts$/,
140
        loaders: [
141
          '@ngtools/webpack'
142
        ]
143
      }
144
    );
145
  }
146
  return webpackMerge(defaultConfig, webpackConfig);
147
};
(11-11/11)