Project

General

Profile

1
var webpack = require('webpack');
2
var path = require('path');
3
var webpackMerge = require('webpack-merge');
4

    
5
// Webpack Config
6
var webpackConfig = {
7
    entry: {
8
        'main': './app/main.ts',
9
    },
10

    
11
    output: {
12
        publicPath: '/dist/',
13
        path: path.resolve(__dirname, './dist'),
14
    },
15

    
16
    plugins: [
17
        new webpack.ContextReplacementPlugin(
18
            // The (\\|\/) piece accounts for path separators in *nix and Windows
19
            /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
20
            path.resolve(__dirname, './'),
21
            {
22
                // your Angular Async Route paths relative to this root directory
23
            }
24
        ),
25
        new webpack.ProvidePlugin({
26
            jQuery: 'jquery',
27
            $: 'jquery',
28
            jquery: 'jquery'
29
        })
30
    ],
31

    
32
    module: {
33
        loaders: [
34
            // .ts files for TypeScript
35
            {
36
                test: /\.ts$/,
37
                loaders: [
38
                    'awesome-typescript-loader',
39
                    'angular2-template-loader',
40
                    'angular2-router-loader'
41
                ]
42
            },
43
            { test: /\.css$/, loaders: ['to-string-loader', 'css-loader'] },
44
            { test: /\.html$/, loader: 'raw-loader' },
45
            { test: /\.scss$/, loaders: ['style', 'css', 'postcss', 'sass'] },
46
            { test: /\.(woff2?|ttf|eot|svg)$/, loader: 'url?limit=10000' },
47
            { test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery' }
48
        ]
49
    }
50

    
51
};
52

    
53

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

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

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

    
69
    devServer: {
70
        historyApiFallback: true,
71
        watchOptions: { aggregateTimeout: 300, poll: 1000 },
72
        headers: {
73
            "Access-Control-Allow-Origin": "*",
74
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
75
            "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
76
        }
77
    },
78

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

    
91

    
92
module.exports = function(env) {
93
    console.log(env);
94
    // if(!env.release && env.release != true) {
95
    //     webpackConfig.plugins.push(
96
    //         new webpack.DefinePlugin({"process.env" : {
97
    //             PRODUCTION: JSON.stringify(true),
98
    //             API_ENDPOINT : JSON.stringify(process.env.API_ENDPOINT || "http://localhost:5000")
99
    //         }})
100
    //     );
101
    // } else {
102
        webpackConfig.plugins.push(
103
            new webpack.DefinePlugin({"process.env" : {
104
                PRODUCTION: JSON.stringify(true),
105
                API_ENDPOINT : JSON.stringify(process.env.API_ENDPOINT || "/api/")
106
            }})
107
        );
108
    // }
109
    return webpackMerge(defaultConfig, webpackConfig);
110
};
(7-7/7)