-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
123 lines (109 loc) · 3.58 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var dotenv = require('dotenv');
dotenv.config();
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var PORT = 8080;
var HOST = 'localhost'
var argv = process.argv || [];
if (argv.indexOf('--port') > -1) {
PORT = argv[argv.indexOf('--port') + 1]
}
if (argv.indexOf('--host') > -1) {
HOST = argv[argv.indexOf('--host') + 1]
}
var isProduction = argv.indexOf('--production') != -1;
var isBuildForCordova = argv.indexOf('--cordova') != -1;
var isRunningOnServer = argv.find(v => v.includes('webpack-dev-server'))
var plugins = [];
var entryPoints = [
'./styles/index.css',
'./src/test-index.tsx'
];
if (isProduction) {
// Adding Production environment specific features.
plugins.push(
new webpack.optimize.UglifyJsPlugin({ // Used for minification of .js and .css files.
minimize: true,
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
'API_URL': JSON.stringify(process.env.API_URL),
'SERVER_URL': JSON.stringify(process.env.SERVER_URL),
}
})
);
} else {
// Adding Development environment specific features.
if (isRunningOnServer) {
entryPoints.push(
'webpack/hot/only-dev-server' // Used to enable hot reloading in webpack.
);
}
plugins.push(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development'),
'API_URL': JSON.stringify(process.env.API_URL),
'SERVER_URL': JSON.stringify(process.env.SERVER_URL),
}
})
);
}
plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.ejs'
}),
new ExtractTextPlugin({filename: 'style.css', allChunks: true}),
new webpack.optimize.ModuleConcatenationPlugin()
);
var config = {
entry: entryPoints,
output: {
path: path.join(__dirname, 'dist'),
filename: isProduction ? 'bundle.[hash].min.js' : 'bundle.js',
publicPath: '/'
},
devServer: {
historyApiFallback: true
},
devtool: 'source-map',
resolve: {
modules: [
path.resolve('./src'),
"node_modules"
],
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.css', '.json', '.ejs'],
enforceExtension: false
},
module: {
loaders: [
{test: /\.tsx?$/, loader: 'tslint-loader', exclude: /node_modules/, enforce: 'pre'},
{test: /\.tsx?$/, exclude: /node_modules/, loaders: ['react-hot-loader/webpack', 'ts-loader']},
{test: /\.css$/, loader: ExtractTextPlugin.extract({fallback: 'style-loader', use: 'css-loader'})},
{test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, loader: 'url-loader?limit=1024&name=fonts/[name].[ext]'},
{test: /\.(jpg|jpeg|gif|png)$/, loader: 'url-loader?limit=10&mimetype=image/(jpg|jpeg|gif|png)&name=images/[name].[ext]'},
{test: /\.json$/, loader: 'json-loader' },
{test: /\.ejs$/, loader: 'ejs-loader' }
],
noParse: /node_modules\/json-schema\/lib\/validate\.js/
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
},
plugins: plugins,
};
if (isRunningOnServer) {
config.devServer = {
historyApiFallback: true
}
}
module.exports = config;