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://194.177.192.121:8380/uoa-repository-manager-service"),
101
          FAQ_ENDPOINT: JSON.stringify(process.env.FAQ_ENDPOINT || "http://83.212.101.85:5555/api/"),
102
          CONNECTOR_API_ENDPOINT: JSON.stringify(process.env.CONNECTOR_API_ENDPOINT || "http://localhost:8888/content-connector-service"),
103
          WORKFLOW_API_ENDPOINT: JSON.stringify(process.env.WORKFLOW_API_ENDPOINT || "https://dev.openminted.eu:8881"),
104
          OIDC_ENDPOINT: JSON.stringify(process.env.OIDC_ENDPOINT || "http://localhost:8080/omtd-registry/openid_connect_login"),
105
          AAI_ENDPOINT: JSON.stringify(process.env.AAI_ENDPOINT || "https://aai.openminted.eu/oidc")
106
        }
107
      })
108
    );
109
    webpackConfig.module.loaders.push(
110
      {
111
        test: /\.ts$/,
112
        loaders: [
113
          'awesome-typescript-loader',
114
          'angular2-template-loader',
115
          'angular2-router-loader'
116
        ]
117
      }
118
    );
119
  } else {
120
    webpackConfig.plugins.push(
121
      new AotPlugin({
122
        tsConfigPath: 'tsconfig.json',
123
        entryModule: path.resolve(__dirname, './app/app.module#AppModule')
124
      })
125
    );
126
    webpackConfig.plugins.push(
127
      new webpack.DefinePlugin({
128
        "process.env": {
129
          PRODUCTION: JSON.stringify(true),
130
          API_ENDPOINT: JSON.stringify("/api"),
131
          FAQ_ENDPOINT: JSON.stringify("/faq"),
132
          CONNECTOR_API_ENDPOINT: JSON.stringify("/connector"),
133
          WORKFLOW_API_ENDPOINT: JSON.stringify("/workflow"),
134
          OIDC_ENDPOINT: JSON.stringify("/api/openid_connect_login"),
135
          AAI_ENDPOINT: JSON.stringify("https://aai.openminted.eu/oidc")
136
        }
137
      })
138
    );
139
    webpackConfig.module.loaders.push(
140
      {
141
        test: /\.ts$/,
142
        loaders: [
143
          '@ngtools/webpack'
144
        ]
145
      }
146
    );
147
  }
148
  return webpackMerge(defaultConfig, webpackConfig);
149
};
(11-11/11)