2016-03-14 08:50:46 -04:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2016-05-13 16:17:07 -04:00
|
|
|
const nodeExternals = require('webpack-node-externals');
|
2016-03-14 08:50:46 -04:00
|
|
|
|
2016-07-15 08:57:52 -04:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2016-03-14 08:50:46 -04:00
|
|
|
|
2016-03-18 08:48:26 -04:00
|
|
|
const NPM_TARGET = process.env.npm_lifecycle_event; //eslint-disable-line no-process-env
|
|
|
|
|
|
|
|
|
|
var DEV = false;
|
2016-03-29 18:32:15 -04:00
|
|
|
var FULLMAP = false;
|
2016-05-13 16:17:07 -04:00
|
|
|
var TEST = false;
|
2016-03-29 18:32:15 -04:00
|
|
|
if (NPM_TARGET === 'run' || NPM_TARGET === 'run-fullmap') {
|
2016-03-18 08:48:26 -04:00
|
|
|
DEV = true;
|
2016-03-29 18:32:15 -04:00
|
|
|
if (NPM_TARGET === 'run-fullmap') {
|
|
|
|
|
FULLMAP = true;
|
|
|
|
|
}
|
2016-03-18 08:48:26 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:17:07 -04:00
|
|
|
if (NPM_TARGET === 'test') {
|
|
|
|
|
DEV = false;
|
|
|
|
|
TEST = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 09:28:18 -04:00
|
|
|
const STANDARD_EXCLUDE = [
|
|
|
|
|
path.join(__dirname, 'node_modules'),
|
|
|
|
|
path.join(__dirname, 'non_npm_dependencies')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var MYSTATS = {
|
|
|
|
|
|
|
|
|
|
// Add asset Information
|
|
|
|
|
assets: false,
|
|
|
|
|
|
|
|
|
|
// Sort assets by a field
|
|
|
|
|
assetsSort: '',
|
|
|
|
|
|
|
|
|
|
// Add information about cached (not built) modules
|
|
|
|
|
cached: true,
|
|
|
|
|
|
|
|
|
|
// Show cached assets (setting this to `false` only shows emitted files)
|
|
|
|
|
cachedAssets: true,
|
|
|
|
|
|
|
|
|
|
// Add children information
|
|
|
|
|
children: true,
|
|
|
|
|
|
|
|
|
|
// Add chunk information (setting this to `false` allows for a less verbose output)
|
|
|
|
|
chunks: true,
|
|
|
|
|
|
|
|
|
|
// Add built modules information to chunk information
|
|
|
|
|
chunkModules: true,
|
|
|
|
|
|
|
|
|
|
// Add the origins of chunks and chunk merging info
|
|
|
|
|
chunkOrigins: true,
|
|
|
|
|
|
|
|
|
|
// Sort the chunks by a field
|
|
|
|
|
chunksSort: '',
|
|
|
|
|
|
|
|
|
|
// `webpack --colors` equivalent
|
|
|
|
|
colors: true,
|
|
|
|
|
|
|
|
|
|
// Display the distance from the entry point for each module
|
|
|
|
|
depth: true,
|
|
|
|
|
|
|
|
|
|
// Display the entry points with the corresponding bundles
|
|
|
|
|
entrypoints: true,
|
|
|
|
|
|
|
|
|
|
// Add errors
|
|
|
|
|
errors: true,
|
|
|
|
|
|
|
|
|
|
// Add details to errors (like resolving log)
|
|
|
|
|
errorDetails: true,
|
|
|
|
|
|
|
|
|
|
// Exclude modules which match one of the given strings or regular expressions
|
|
|
|
|
exclude: [],
|
|
|
|
|
|
|
|
|
|
// Add the hash of the compilation
|
|
|
|
|
hash: true,
|
|
|
|
|
|
|
|
|
|
// Set the maximum number of modules to be shown
|
|
|
|
|
maxModules: 0,
|
|
|
|
|
|
|
|
|
|
// Add built modules information
|
|
|
|
|
modules: false,
|
|
|
|
|
|
|
|
|
|
// Sort the modules by a field
|
|
|
|
|
modulesSort: '!size',
|
|
|
|
|
|
|
|
|
|
// Show performance hint when file size exceeds `performance.maxAssetSize`
|
|
|
|
|
performance: true,
|
|
|
|
|
|
|
|
|
|
// Show the exports of the modules
|
|
|
|
|
providedExports: true,
|
|
|
|
|
|
|
|
|
|
// Add public path information
|
|
|
|
|
publicPath: true,
|
|
|
|
|
|
|
|
|
|
// Add information about the reasons why modules are included
|
|
|
|
|
reasons: true,
|
|
|
|
|
|
|
|
|
|
// Add the source code of modules
|
|
|
|
|
source: true,
|
|
|
|
|
|
|
|
|
|
// Add timing information
|
|
|
|
|
timings: true,
|
|
|
|
|
|
|
|
|
|
// Show which exports of a module are used
|
|
|
|
|
usedExports: true,
|
|
|
|
|
|
|
|
|
|
// Add webpack version information
|
|
|
|
|
version: true,
|
|
|
|
|
|
|
|
|
|
// Add warnings
|
|
|
|
|
warnings: true,
|
|
|
|
|
|
|
|
|
|
// Filter warnings to be shown (since webpack 2.4.0),
|
|
|
|
|
// can be a String, Regexp, a function getting the warning and returning a boolean
|
|
|
|
|
// or an Array of a combination of the above. First match wins.
|
|
|
|
|
warningsFilter: ''
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-18 08:48:26 -04:00
|
|
|
var config = {
|
2017-04-25 11:46:02 -04:00
|
|
|
entry: ['babel-polyfill', 'whatwg-fetch', './root.jsx', 'root.html'],
|
2016-03-14 08:50:46 -04:00
|
|
|
output: {
|
2017-05-18 09:28:18 -04:00
|
|
|
path: path.join(__dirname, 'dist'),
|
2016-03-14 08:50:46 -04:00
|
|
|
publicPath: '/static/',
|
2016-07-15 08:57:52 -04:00
|
|
|
filename: '[name].[hash].js',
|
|
|
|
|
chunkFilename: '[name].[chunkhash].js'
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
module: {
|
2017-05-18 09:28:18 -04:00
|
|
|
rules: [
|
2016-03-14 08:50:46 -04:00
|
|
|
{
|
2017-04-25 11:46:02 -04:00
|
|
|
test: /\.(js|jsx)?$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
exclude: STANDARD_EXCLUDE,
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
presets: [
|
|
|
|
|
'react',
|
|
|
|
|
['es2015', {modules: false}],
|
|
|
|
|
'stage-0'
|
|
|
|
|
],
|
|
|
|
|
plugins: ['transform-runtime'],
|
|
|
|
|
cacheDirectory: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.json$/,
|
2016-07-19 18:28:04 +02:00
|
|
|
exclude: /manifest\.json$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'json-loader'
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
2016-07-19 18:28:04 +02:00
|
|
|
{
|
|
|
|
|
test: /manifest\.json$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'file-loader?name=files/[hash].[ext]'
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-07-19 18:28:04 +02:00
|
|
|
},
|
2016-03-14 08:50:46 -04:00
|
|
|
{
|
2016-10-04 08:56:01 -04:00
|
|
|
test: /(node_modules|non_npm_dependencies)(\\|\/).+\.(js|jsx)$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'imports-loader',
|
|
|
|
|
options: {
|
|
|
|
|
$: 'jquery',
|
|
|
|
|
jQuery: 'jquery'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.scss$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'style-loader'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'css-loader'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'sass-loader',
|
|
|
|
|
options: {
|
|
|
|
|
includePaths: ['node_modules/compass-mixins/lib']
|
|
|
|
|
}
|
2017-03-13 13:58:12 -04:00
|
|
|
}
|
2017-05-18 09:28:18 -04:00
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'style-loader'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'css-loader'
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
{
|
2016-03-24 16:41:53 -04:00
|
|
|
test: /\.(png|eot|tiff|svg|woff2|woff|ttf|gif|mp3|jpg)$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'file-loader',
|
|
|
|
|
options: {
|
|
|
|
|
name: 'files/[hash].[ext]'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'image-webpack-loader',
|
|
|
|
|
options: {}
|
|
|
|
|
}
|
2016-06-30 12:26:04 -04:00
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.html$/,
|
2017-05-18 09:28:18 -04:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'html-loader',
|
|
|
|
|
options: {
|
|
|
|
|
attrs: 'link:href'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
2017-05-18 09:28:18 -04:00
|
|
|
resolve: {
|
|
|
|
|
modules: [
|
|
|
|
|
'node_modules',
|
|
|
|
|
'non_npm_dependencies',
|
|
|
|
|
path.resolve(__dirname)
|
|
|
|
|
],
|
|
|
|
|
alias: {
|
|
|
|
|
jquery: 'jquery/dist/jquery',
|
|
|
|
|
superagent: 'node_modules/superagent/lib/client'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
performance: {
|
|
|
|
|
hints: 'warning'
|
|
|
|
|
},
|
|
|
|
|
target: 'web',
|
|
|
|
|
stats: MYSTATS,
|
2016-03-14 08:50:46 -04:00
|
|
|
plugins: [
|
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
|
'window.jQuery': 'jquery'
|
|
|
|
|
}),
|
2016-03-16 23:00:33 -04:00
|
|
|
new webpack.LoaderOptionsPlugin({
|
2016-03-18 08:48:26 -04:00
|
|
|
minimize: !DEV,
|
2016-03-16 23:00:33 -04:00
|
|
|
debug: false
|
2016-05-04 10:10:19 -04:00
|
|
|
}),
|
2016-06-22 10:30:01 -04:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
|
minChunks: 2,
|
2016-06-30 12:26:04 -04:00
|
|
|
children: true
|
2016-03-16 23:00:33 -04:00
|
|
|
})
|
2017-05-18 09:28:18 -04:00
|
|
|
]
|
2016-03-14 08:50:46 -04:00
|
|
|
};
|
2016-03-18 08:48:26 -04:00
|
|
|
|
|
|
|
|
// Development mode configuration
|
|
|
|
|
if (DEV) {
|
2016-03-29 18:32:15 -04:00
|
|
|
if (FULLMAP) {
|
|
|
|
|
config.devtool = 'source-map';
|
|
|
|
|
} else {
|
2017-05-18 09:28:18 -04:00
|
|
|
config.devtool = 'cheap-module-eval-source-map';
|
2016-03-29 18:32:15 -04:00
|
|
|
}
|
2016-03-18 08:48:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Production mode configuration
|
|
|
|
|
if (!DEV) {
|
|
|
|
|
config.devtool = 'source-map';
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
|
'screw-ie8': true,
|
|
|
|
|
mangle: {
|
|
|
|
|
toplevel: false
|
|
|
|
|
},
|
|
|
|
|
compress: {
|
|
|
|
|
warnings: false
|
|
|
|
|
},
|
2016-11-21 20:56:36 -05:00
|
|
|
comments: false,
|
|
|
|
|
sourceMap: true
|
2016-03-18 08:48:26 -04:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new webpack.optimize.OccurrenceOrderPlugin(true)
|
|
|
|
|
);
|
2016-11-21 20:56:36 -05:00
|
|
|
config.plugins.push(
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
'process.env': {
|
|
|
|
|
NODE_ENV: JSON.stringify('production')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
2016-03-18 08:48:26 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-13 16:17:07 -04:00
|
|
|
// Test mode configuration
|
|
|
|
|
if (TEST) {
|
2016-07-15 08:57:52 -04:00
|
|
|
config.entry = ['babel-polyfill', './root.jsx'];
|
|
|
|
|
config.target = 'node';
|
2016-05-13 16:17:07 -04:00
|
|
|
config.externals = [nodeExternals()];
|
2016-07-15 08:57:52 -04:00
|
|
|
} else {
|
2016-11-17 09:02:33 -05:00
|
|
|
// For some reason these break mocha. So they go here.
|
2016-07-15 08:57:52 -04:00
|
|
|
config.plugins.push(
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
|
filename: 'root.html',
|
|
|
|
|
inject: 'head',
|
|
|
|
|
template: 'root.html'
|
|
|
|
|
})
|
|
|
|
|
);
|
2016-11-17 09:02:33 -05:00
|
|
|
config.plugins.push(
|
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
|
{from: 'images/emoji', to: 'emoji'},
|
|
|
|
|
{from: 'images/logo-email.png', to: 'images'},
|
|
|
|
|
{from: 'images/circles.png', to: 'images'},
|
|
|
|
|
{from: 'images/favicon', to: 'images/favicon'},
|
|
|
|
|
{from: 'images/appIcons.png', to: 'images'}
|
|
|
|
|
])
|
|
|
|
|
);
|
2016-05-13 16:17:07 -04:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 08:48:26 -04:00
|
|
|
module.exports = config;
|