reactatouille
Version:
Reactatouille is a command-line tool to help quickly start and build a new React project, using Redux, Webpack, Gulp (You can add your own tasks, yo!), HMR/Hot Module Reload, Sass (architecture best practices), Jest, Enzyme, popmotion, Redux devtools (bro
129 lines (126 loc) • 3.46 kB
JavaScript
var config = require('config')
var fs = require('fs')
var path = require('path')
var webpack = require('webpack')
var CompressionPlugin = require('compression-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var rootDir = path.resolve(__dirname, '../')
var OfflinePlugin = require('offline-plugin')
var AutoDllPlugin = require('autodll-webpack-plugin')
// https://github.com/lorenwest/node-config/wiki/Webpack-Usage
fs.writeFileSync(path.resolve(rootDir, 'config/client.development.json'), JSON.stringify(config))
module.exports = {
devtool: 'source-map',
context: path.resolve(rootDir, 'src'),
entry: ['babel-polyfill', './js/index.js'],
output: {
path: path.join(rootDir, '/dist/production'),
publicPath: '',
filename: 'assets/js/bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
minimize: true,
sourceMap: true
}
}, 'sass-loader?sourceMap'],
publicPath: '../../'
})
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './assets/fonts/',
context: path.join(rootDir, '/dist/production')
}
}
]
},
{
test: /\.(jpg|png|gif|svg)$/i,
exclude: /(node_modules)/,
use: [
'file-loader?name=[path][name].[ext]'
]
},
{
test: /\.(webm|mp4)$/,
use: [
'file-loader?name=[path][name].[ext]&emitFile=false'
]
}
]
},
plugins: [
new ExtractTextPlugin('assets/css/[name].min.css'),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
'BUILDER': true
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: false, // if true, causes issue with gsap `https://greensock.com/forums/topic/14387-webpack-gsap-error/`
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
drop_console: true
},
output: {
comments: false
},
exclude: [/\.min\.js$/gi] // skip pre-minified libs
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new AutoDllPlugin({
filename: 'vendors.dll.js',
path: 'assets/js',
entry: {
vendor: [
'react',
'react-dom',
'react-redux',
'redux',
'history/createBrowserHistory',
'babel-polyfill'
]
}
}),
new OfflinePlugin() // it's always better if OfflinePlugin is the last plugin added
],
resolve: {
alias: {
config: path.resolve(rootDir, 'config/client.development.json')
}
}
}