-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
160 lines (143 loc) · 4.17 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*eslint no-process-env:0, camelcase:0*/
'use strict';
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const isProduction = (process.env.NODE_ENV || 'dev') === 'prod';
const isLocal = process.env.NODE_ENV === 'local';
const dest = 'dist';
const absDest = root(dest);
const contentfulDevConfig = JSON.parse(
fs.readFileSync('./contentful-local.json') // eslint-disable-line no-sync
);
const twitterConfig = JSON.parse(
fs.readFileSync('./twitter.json') //eslint-disable-line no-sync
);
const config = {
// devtool: isProduction ? 'eval' : 'source-map',
debug: false,
verbose: true,
displayErrorDetails: true,
context: __dirname,
stats: {
colors: true,
reasons: true
},
resolve: {
cache: false,
root: __dirname,
extensions: ['', '.ts', '.js', '.json']
},
entry: {
common: [
// Angular 2 Deps + common libs - I split it into separated entries but
// current version of webpack has problem with that
// due https://github.com/webpack/webpack/issues/1016
'es6-shim',
'es6-promise',
'zone.js',
'reflect-metadata',
'rxjs',
'@angular/common',
'@angular/core',
'@angular/router',
'@angular/http',
'@angular/compiler',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'moment',
'ng2-bootstrap',
'ng2-contentful-blog',
'ng2-contentful'
],
app: 'app'
},
output: {
path: absDest,
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js'
},
module: {
loaders: [
{test: /\.(png|svg)$/, loader: 'raw'},
{test: /\.md$/, loader: 'html?minimize=false!markdown'},
{test: /\.json$/, loader: 'json'},
{test: /\.css$/, loader: 'to-string!css?-url'},
{test: /\.styl$/, loader: 'to-string!css?-url!stylus'},
{test: /\.html$/, loader: 'raw'},
{
test: /\.ts$/,
loader: 'ts',
query: {
compilerOptions: {
removeComments: true,
noEmitHelpers: false
}
},
exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/]
}
],
noParse: [
/rtts_assert\/src\/rtts_assert/,
/reflect-metadata/,
/zone\.js\/dist/,
/codebird/
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: Infinity
}),
new CopyWebpackPlugin([{from: 'app/assets', to: 'assets'}]),
new HtmlWebpackPlugin({
template: 'app/index.html.template',
googleAnalytics: {
trackingId: isProduction ? 'UA-67908993-3' : 'UA-XXXXX-Y',
pageViewOnLoad: false
}
}),
new webpack.DefinePlugin({
CONTENTFUL_ACCESS_TOKEN:
JSON.stringify(process.env.CONTENTFUL_ACCESS_TOKEN) || JSON.stringify(contentfulDevConfig.accessToken),
CONTENTFUL_SPACE_ID:
JSON.stringify(process.env.CONTENTFUL_SPACE_ID) || JSON.stringify(contentfulDevConfig.spaceId),
CONTENTFUL_HOST:
JSON.stringify(process.env.CONTENTFUL_HOST) || JSON.stringify(contentfulDevConfig.host),
TWITTER_CONSUMER_KEY: JSON.stringify(twitterConfig.consumerKey),
TWITTER_CONSUMER_SECRET: JSON.stringify(twitterConfig.consumerSecret),
TWITTER_ACCESS_TOKEN_KEY: JSON.stringify(twitterConfig.accessTokenKey),
TWITTER_ACCESS_TOKEN_SECRET: JSON.stringify(twitterConfig.accessTokenSecret)
})
]
};
function pushPlugins(conf) {
if (isLocal) {
return;
}
conf.plugins.push(
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: false,
comments: false,
compress: {screw_ie8: true}
}),
new CompressionPlugin({
asset: '{file}.gz',
algorithm: 'gzip',
regExp: /\.js$|\.html|\.css|.map$/,
threshold: 10240,
minRatio: 0.8
})
);
}
pushPlugins(config);
module.exports = config;
function root(location) {
return path.join(__dirname, location);
}