forked from tracking-exposed/web-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
186 lines (152 loc) · 4.88 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* eslint-disable strict, no-console, object-shorthand */
/* eslint-disable import/no-extraneous-dependencies, import/newline-after-import */
'use strict';
const path = require('path');
const exec = require('child_process').exec;
const webpack = require('webpack');
const autoPrefixer = require('autoprefixer');
const combineLoaders = require('webpack-combine-loaders');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
require('dotenv').load({ silent: true });
const LAST_VERSION = 1;
const packageJSON = require('./package.json');
const NODE_ENV = process.env.NODE_ENV || 'development';
const PRODUCTION = NODE_ENV === 'production';
const DEVELOPMENT = NODE_ENV === 'development';
console.log('NODE_ENV [' + process.env.NODE_ENV + '] Prod:', PRODUCTION, 'Devel: ', DEVELOPMENT);
const BUILD = require('child_process').execSync('git rev-parse HEAD').toString().trim();
const PATHS = {
APPS: {
app: path.resolve(__dirname, 'src/app.js'),
background: path.resolve(__dirname, 'src/chrome/background/index.js'),
popup: path.resolve(__dirname, 'src/chrome/popup/index.js')
},
BUILD: path.resolve(__dirname, 'build'),
DIST: path.resolve(__dirname, 'dist'),
NODE_MODULES: path.resolve(__dirname, 'node_modules')
};
/** EXTERNAL DEFINITIONS INJECTED INTO APP **/
var ENV_DEP_SERVER = DEVELOPMENT ? 'http://localhost:8000' : 'https://collector.facebook.tracking.exposed';
var ENV_DEP_WEB = DEVELOPMENT ? 'http://localhost:8000' : 'https://facebook.tracking.exposed';
// var local = 'http://192.168.223.133:8000/';
const DEFINITIONS = {
'process.env': {
DEVELOPMENT: JSON.stringify(DEVELOPMENT),
NODE_ENV: JSON.stringify(NODE_ENV),
API_ROOT: JSON.stringify(ENV_DEP_SERVER + '/api/v' + LAST_VERSION + '/'),
WEB_ROOT: JSON.stringify(ENV_DEP_WEB),
VERSION: JSON.stringify(packageJSON.version + (DEVELOPMENT ? '-dev' : '')),
BUILD: JSON.stringify(BUILD),
FLUSH_INTERVAL: JSON.stringify(DEVELOPMENT ? 10000 : 20000)
}
};
/** PLUGINS **/
const PLUGINS = [
new webpack.DefinePlugin(DEFINITIONS),
new webpack.NoErrorsPlugin()
];
const PROD_PLUGINS = [
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
output: {
comments: false
},
sourceMap: true
}),
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true
})
// Add additional production plugins
];
const DEV_PLUGINS = [
new WebpackNotifierPlugin({
// My notification daemon displays "critical" messages only.
// Dunno if this is the case for every Ubuntu machine.
urgency: 'critical',
title: 'fbtrex',
contentImage: path.join(__dirname, 'icons', 'fbtrex128.png'),
timeout: 2,
alwaysNotify: true
})
];
const EXTRACT_CSS_PLUGIN = new ExtractTextPlugin(
'styles.css', {
allChunks: true
}
);
PLUGINS.push(EXTRACT_CSS_PLUGIN);
if (PRODUCTION) {
PLUGINS.push(...PROD_PLUGINS);
} else if (DEVELOPMENT) {
console.log('Development, using as environment variables: ' +
JSON.stringify(DEFINITIONS['process.env']));
PLUGINS.push(...DEV_PLUGINS);
}
/** LOADERS **/
const JS_LOADER = combineLoaders([
{
loader: 'babel',
query: {
cacheDirectory: true
}
}
// Add additional JS loaders
]);
const CSS_LOADER = combineLoaders([
{
loader: 'css',
query: {
sourceMap: true
}
},
{ loader: 'postcss' },
{
loader: 'sass',
query: {
precision: '8', // If you use bootstrap, must be >= 8. See https://github.com/twbs/bootstrap-sass#sass-number-precision
outputStyle: 'expanded',
sourceMap: true
}
}
// Add additional style / CSS loaders
]);
// Add additional loaders to handle other formats (ie. images, svg)
const LOADERS = [
{
test: /\.jsx?$/,
exclude: [PATHS.NODE_MODULES],
loader: JS_LOADER
}, {
test: /\.s[ac]ss$/,
exclude: [PATHS.NODE_MODULES],
loader: ExtractTextPlugin.extract('style', CSS_LOADER)
}
// Add additional loader specifications
];
/** EXPORTED WEBPACK CONFIG **/
const config = {
entry: PATHS.APPS,
output: {
path: PRODUCTION ? PATHS.DIST : PATHS.BUILD,
filename: '[name].js'
},
debug: !PRODUCTION,
// devtool: PRODUCTION ? '#source-map' : '#inline-source-map',
devtool: PRODUCTION ? null : '#inline-source-map',
target: 'web',
resolve: {
extensions: ['', '.js', '.jsx'],
modules: ['node_modules'] // Don't use absolute path here to allow recursive matching
},
plugins: PLUGINS,
module: {
loaders: LOADERS
},
postcss: [autoPrefixer()]
};
module.exports = config;