Created
June 2, 2016 19:31
-
-
Save z4o4z/a36fb809991ede65e9efe8b6716ed45d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let path = require('path'); | |
let args = require('yargs').argv; | |
let webpack = require('webpack'); | |
let HtmlWebpackPlugin = require('html-webpack-plugin'); | |
let ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
let CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const PATH_DIST = path.join(__dirname, 'dist'); | |
const ENV = args.e || args.env || args.environment || 'dev'; | |
const IS_LOC = ENV === 'loc'; | |
const IS_DEV = ENV === 'dev'; | |
const IS_PROD = ENV === 'prod'; | |
var htmlWebpackPlugins = []; | |
let entry = { | |
index: ['babel-polyfill', path.join(__dirname, 'src', 'index.js')] | |
}; | |
let output = { | |
path: PATH_DIST, | |
filename: '[name].js', | |
library: 'App' | |
}; | |
if (IS_LOC) { | |
let WDV_CLIENT = 'webpack-dev-server/client?http://localhost:8080'; | |
let W_HOT = 'webpack/hot/only-dev-server'; | |
for (let chunk in entry) { | |
if (entry.hasOwnProperty(chunk)) { | |
entry[chunk] = [WDV_CLIENT, W_HOT, ...entry[chunk]] | |
} | |
} | |
} | |
for (let chunk in entry) { | |
if (entry.hasOwnProperty(chunk)) { | |
htmlWebpackPlugins.push(new HtmlWebpackPlugin({ | |
template: path.join(__dirname, 'src', 'index.html'), | |
chunks: [chunk], | |
title: chunk, | |
filename: chunk + '.html' | |
})); | |
} | |
} | |
module.exports = { | |
entry, | |
devtool: (IS_DEV || IS_LOC) ? 'cheap-inline-module-source-map' : '', | |
watch: IS_LOC, | |
watchOptions: { | |
aggregateTimeout: 100 | |
}, | |
output, | |
resolve: { | |
modulesDirectories: ['node_modules'], | |
extensions: ['', '.js'], | |
alias: { | |
lvis: path.join(__dirname, 'node_modules', 'lvis-api', 'lvis.js'), | |
jquery: path.join(__dirname, 'node_modules', 'jquery', 'dist', 'jquery.js'), | |
backbone: path.join(__dirname, 'node_modules', 'backbone', 'backbone.js'), | |
marionette: path.join(__dirname, 'node_modules', 'backbone.marionette', 'lib', 'backbone.marionette.js'), | |
zeroclipboard: path.join(__dirname, 'node_modules', 'zeroclipboard', 'dist', 'ZeroClipboard.js'), | |
scriptjs: path.join(__dirname, 'node_modules', 'scriptjs', 'dist', 'script.js'), | |
interact: path.join(__dirname, 'node_modules', 'interact.js', 'dist', 'interact.js') | |
} | |
}, | |
module: { | |
loaders: [{ | |
test: /\.js$/, | |
exclude: /(node_modules)/, | |
loader: 'babel', | |
query: { | |
presets: ['es2015', 'stage-1'], | |
plugins: ['transform-runtime'] | |
} | |
}, { | |
test: /lvis.js/, | |
loader: 'imports?this=>window!exports?LViS' | |
}, { | |
test: /lvis-leaderboard.min.js/, | |
loader: 'imports?this=>window' | |
}, { | |
test: /\.json$/, | |
loader: 'json' | |
}, { | |
test: /\.scss$/, | |
loader: ExtractTextPlugin.extract("style", "css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!autoprefixer!resolve-url!sass") | |
}, { | |
test: /\.css$/, | |
loader: ExtractTextPlugin.extract("style", "css!autoprefixer!resolve-url") | |
}, { | |
test: /\.hbs$/, | |
loader: "handlebars-loader", | |
query: { | |
helperDirs: [ | |
path.join(__dirname, 'src', 'helpers') | |
] | |
} | |
}, { | |
test: /\.eot|\.otf/, | |
loader: "file-loader" | |
}, { | |
test: /\.(woff|woff2)$/, | |
loader: "url?prefix=font/&limit=5000" | |
}, { | |
test: /\.ttf$/, | |
loader: "url?limit=10000&mimetype=application/octet-stream" | |
}, { | |
test: /\.svg$/, | |
loader: "url?limit=10000&mimetype=image/svg+xml" | |
}, { | |
test: /\.gif$/, | |
loader: "url?limit=10000&mimetype=image/gif" | |
}, { | |
test: /\.jpg$/, | |
loader: "url?limit=10000&mimetype=image/jpg" | |
}, { | |
test: /\.png$/, | |
loader: "url?limit=10000&mimetype=image/png" | |
}] | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NoErrorsPlugin(), | |
new webpack.DefinePlugin({ | |
IS_DEV: JSON.stringify(IS_DEV), | |
IS_LOC: JSON.stringify(IS_LOC), | |
IS_PROD: JSON.stringify(IS_PROD) | |
}), | |
new ExtractTextPlugin('style.css'), | |
new CopyWebpackPlugin([ | |
{ | |
from: path.join(__dirname, 'node_modules', 'zeroclipboard', 'dist', 'ZeroClipboard.swf'), | |
to: path.join(__dirname, 'ZeroClipboard.swf') | |
} | |
]), | |
...htmlWebpackPlugins | |
], | |
devServer: { | |
contentBase: PATH_DIST, | |
host: 'localhost', // default | |
port: 8080, // default | |
hot: true, | |
historyApiFallback: { | |
index: '/index.html' | |
}, | |
proxy: [{ | |
path: '/upload/', | |
target: 'http://localhost:8081' | |
},{ | |
path: '/images/*', | |
target: 'http://d1ntfop85sum9q.cloudfront.net' | |
},{ | |
path: '/imgml/*', | |
target: 'http://img.uefa.com' | |
}] | |
} | |
}; | |
if (!IS_LOC && !IS_DEV) { | |
module.exports.plugins.push( | |
new webpack.optimize.UglifyJsPlugin({ | |
minimize: true, | |
comments: false | |
}) | |
); | |
new webpack.optimize.DedupePlugin(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment