Skip to content

Instantly share code, notes, and snippets.

@lazandrei19
Created April 9, 2017 18:40
Show Gist options
  • Save lazandrei19/e2e0ffcb762998dcbfdb70b1cdaa22a6 to your computer and use it in GitHub Desktop.
Save lazandrei19/e2e0ffcb762998dcbfdb70b1cdaa22a6 to your computer and use it in GitHub Desktop.
{
"presets": [
["stage-0"],
["env", {"modules": false}],
"react"
],
"plugins": [
"react-hot-loader/babel"
//"react-css-modules"
]
}
module.exports = {
plugins: [
require ('autoprefixer')
]
}
const path = require('path');
const webpack = require('webpack');
const env = require ('node-env-file');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
env (path.join(__dirname, ".env"));
const isProd = process.env.NODE_ENV === 'prod';
const prodCss = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]'
}}, 'postcss-loader',
'sass-loader'
],
publicPath: '/dist'
});
const devCss = [
'style-loader', {
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]'
}
},
'postcss-loader',
'sass-loader'
];
const css = isProd? prodCss : devCss;
const id = isProd? '[hash]' : 'bundle';
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/app.js',
],
output: {
path: path.join (__dirname, 'dist'),
filename: '[name].' + id + '.js',
chunkFilename: '[id].' + id + '.js'
},
module: {
rules: [{
test: /\.(sa|s?c)ss$/,
use: css
}, {
test: /\.jsx?$/,
exclude: /node_modules/,
use: 'babel-loader'
}]
},
plugins: [
new HtmlWebpackPlugin ({
title: 'Webpack test page',
template: 'src/index.html',
cache: true
}),
new ExtractTextPlugin({
filename: '[name].' + id + '.css',
disable: !isProd,
allChunks: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
})
],
devServer: {
compress: true,
contentBase: path.join (__dirname, 'assets'),
overlay: true,
hot: !isProd,
proxy: {
'/api': {
target: 'http://localhost:3000/',
secure: false
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment