Skip to content

Instantly share code, notes, and snippets.

@vamsiampolu
Created June 18, 2016 05:48
Show Gist options
  • Save vamsiampolu/de0daaaffb4c662220a4dd32907d42e6 to your computer and use it in GitHub Desktop.
Save vamsiampolu/de0daaaffb4c662220a4dd32907d42e6 to your computer and use it in GitHub Desktop.
// paths and constants
var path = require('path')
var SRC_PATH = path.resolve('./src')
var DIST_PATH = path.resolve('./build')
var OUTPUT_FILENAME = '[name].[chunkhash].js'
var DEV_REGEXP = (/(^babel-?.*|.*-plugin$|.*-loader)/)
var DOT_ENV_SAMPLE_PATH = path.resolve('./.env.default')
var DOT_ENV_PATH = path.resolve('./.env')
var pkg = require('./package.json')
var validator = require('webpack-validator')
var merge = require('webpack-merge')
var webpack = require('webpack')
// plugins
var NpmInstallPlugin = require('npm-install-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var template = require('html-webpack-template')
var DotEnvPlugin = require('webpack-dotenv-plugin')
var CleanWebpackPlugin = require('clean-webpack-plugin')
var HotModuleReplacementPlugin = webpack.HotModuleReplacementPlugin
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin
var npmInstallPluginConfig = {
dev: function (module, path) { return DEV_REGEXP.test(module) }
}
var dotenvConfig = {
sample: DOT_ENV_SAMPLE_PATH,
path: DOT_ENV_PATH
}
var hmrConfig = {
multiStep: true
}
var chunks = {
names: ['vendor', 'manifest']
}
var cleanPluginConfig = {
root: process.cwd()
}
var config = {
entry: {
app: SRC_PATH,
vendor: Object.keys(pkg.dependencies)
},
output: {
path: DIST_PATH,
filename: OUTPUT_FILENAME,
chunkFilename: '[chunkhash].js'
},
module: {
preLoaders: [
{
test: /\.jsx?$/,
loader: 'standard',
include: SRC_PATH
}
],
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
include: SRC_PATH,
query: {
cacheDirectory: true
}
}
]
},
devtool: 'eval-source-map',
devServer: {
inline: true,
hot: true,
port: process.env.PORT || 3030,
host: process.env.HOST || '0.0.0.0',
stats: 'errors-only',
historyApiFallback: true,
contentBase: DIST_PATH,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
compress: true
},
plugins: [
new HotModuleReplacementPlugin(hmrConfig),
new NpmInstallPlugin(npmInstallPluginConfig),
new HtmlWebpackPlugin({
inject: false,
mobile: true,
appMountId: 'root',
template: template
}),
new DotEnvPlugin(dotenvConfig),
new CommonsChunkPlugin(chunks),
new CleanWebpackPlugin([DIST_PATH], cleanPluginConfig)
]
}
module.exports = validator(config)
@vczhan
Copy link

vczhan commented Oct 8, 2016

!good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment