This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
webpack.config.www.js
121 lines (116 loc) · 3.79 KB
/
webpack.config.www.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
var BellOnBundlerErrorPlugin = require('bell-on-bundler-error-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var FaviconsWebpackPlugin = require('favicons-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var autoprefixer = require('autoprefixer');
var nested = require('postcss-nested');
var webpack = require('webpack');
module.exports = {
entry: {
index: './www/js/index',
privacy: './www/js/privacy'
},
output: {
path: 'dist-www',
filename: '[name].[hash].js'
},
module: {
loaders: [
{ exclude: 'node_modules', test: /\.(css)$/, loader: ExtractTextPlugin.extract('style', ['css?-autoprefixer&importLoaders=1&sourceMap', 'postcss']) },
{ exclude: 'node_modules', test: /\.(eot|ttf|(woff(2)?(\?v=\d\.\d\.\d)?))$/, loader: 'url?name=fonts/[name].[hash].[ext]&limit=10000' },
{ exclude: 'node_modules', test: /\.(gif|png|jpe?g|svg)$/i, loaders: ['url?name=images/[name].[hash].[ext]&limit=10000', 'image-webpack'] },
{ exclude: 'node_modules', test: /\.(js)$/, loader: 'babel?cacheDirectory' },
{ exclude: 'node_modules', test: /\.(json)/, loader: 'file?name=[name].[hash].[ext]' }
]
},
resolve: {
extensions: extensions(
[''],
['.www', '.browser', ''],
['.json', '.js', '.css']
)
},
bail: process.env.NODE_ENV,
devtool: process.env.NODE_ENV ? 'source-map' : 'cheap-source-map',
devServer: {
port: process.env.PORT,
stats: {
assets: true,
cached: false, // Filters information from devServer.stats.modules
cachedAssets: false, // Filters information from devServer.stats.assets
children: true,
chunks: false,
colors: true,
errorDetails: true,
errors: true,
hash: false,
modules: true,
publicPath: false,
reasons: true,
timings: true,
version: false,
warnings: false
}
},
plugins: [
new webpack.EnvironmentPlugin([
'CHROME_EXTENSION_ID'
]),
new BellOnBundlerErrorPlugin(),
new CleanWebpackPlugin(['dist-www']),
new CopyWebpackPlugin([
{ from: 'assets/images/facebeefbanner.jpg', to: 'images' },
{ from: 'www/CNAME' }
]),
new ExtractTextPlugin('[name].[hash].css'),
new FaviconsWebpackPlugin({ logo: './assets/images/logo.png', title: 'HoverCards', prefix: 'favicons-[hash]/' }),
new HtmlWebpackPlugin({
title: 'HoverCards - More content. Fewer Tabs.',
template: 'www/index.ejs',
inject: false,
chunks: ['index'],
googleAnalytics: process.env.GOOGLE_ANALYTICS_ID && {
trackingId: process.env.GOOGLE_ANALYTICS_ID,
pageViewOnLoad: true
},
mobile: true
}),
new HtmlWebpackPlugin({
title: 'HoverCards - Privacy Policy.',
filename: 'privacy.html',
template: 'www/privacy.ejs',
inject: false,
chunks: ['privacy'],
googleAnalytics: process.env.GOOGLE_ANALYTICS_ID && {
trackingId: process.env.GOOGLE_ANALYTICS_ID,
pageViewOnLoad: true
},
mobile: true
})
],
postcss: function() {
return [nested, autoprefixer];
}
};
if (!process.env.NODE_ENV) {
var DotenvPlugin = require('webpack-dotenv-plugin');
module.exports.plugins = module.exports.plugins.concat([
new DotenvPlugin()
]);
}
function extensions(injections, builds, extensions) {
var results = [''];
[].concat(injections).forEach(function(injection) {
[].concat(builds).forEach(function(build) {
[].concat(extensions).forEach(function(extension) {
if (!injection && !build && !extension) {
return;
}
results.push([injection, build, extension].join(''));
});
});
});
return results;
}