Skip to content

Instantly share code, notes, and snippets.

@Jezternz
Created March 30, 2017 00:12
Show Gist options
  • Save Jezternz/9b077e9e4fce0bfb1e71e3e56e3f2eac to your computer and use it in GitHub Desktop.
Save Jezternz/9b077e9e4fce0bfb1e71e3e56e3f2eac to your computer and use it in GitHub Desktop.
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const productionConfig =
{
devtool: 'source-map',
entry: [
'babel-polyfill',
'./app/web/client.js'
],
output:
{
path: path.join(__dirname, './app/web-static'),
filename: 'script.js',
sourceMapFilename: 'sourcemap.map',
publicPath: '/static/'
},
plugins:
[
new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('production') } }),
new ExtractTextPlugin({ filename: "style.css", disable: false, allChunks: true }),
new webpack.optimize.UglifyJsPlugin({ sourceMap: true, output: { comments: false } }),
new CompressionPlugin({})
],
module:
{
rules:
[
{
test: /\.js$/i,
exclude: /(node_modules)/,
use:
{
loader: 'babel-loader',
query:
{
presets: ["es2015", "react", "stage-0"],
plugins: ["transform-decorators-legacy"]
}
}
},
{
test: /.css$/i,
use: ExtractTextPlugin.extract({
use:
[
"css-loader?modules&camelCase=dashes&localIdentName=[name]_[local]__[hash:base64:5]",
{
loader: "postcss-loader",
options: { plugins: function () { return [require('autoprefixer')]; } }
},
]
})
},
{
test: /\.png$/i,
use: "url-loader?mimetype=image/png&limit=118192"
}
]
}
};
const developmentConfig =
{
devtool: 'inline-source-map',
entry: [
'babel-polyfill',
'webpack-hot-middleware/client',
'./app/web/client.js'
],
output:
{
path: path.join(__dirname, './app/web-static'),
filename: 'script.js',
sourceMapFilename: 'sourcemap.map',
publicPath: '/static/'
},
plugins:
[
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('development') } }),
new ExtractTextPlugin({ filename: "style.css", disable: false, allChunks: true })
],
module:
{
rules:
[
{
test: /\.js$/i,
exclude: /(node_modules)/,
use:
{
loader: 'babel-loader',
query:
{
presets: ["react-hmre", "es2015", "react", "stage-0"],
plugins: ["transform-decorators-legacy"]
}
}
},
{
test: /.css$/i,
use: ExtractTextPlugin.extract({
use:
[
"css-loader?modules&camelCase=dashes&localIdentName=[name]_[local]__[hash:base64:5]",
{
loader: "postcss-loader",
options: { plugins: function () { return [require('autoprefixer')]; } }
},
]
})
},
{
test: /\.png$/i,
use: "url-loader?mimetype=image/png&limit=118192"
}
]
}
};
module.exports = process.env.NODE_ENV === "development" ? developmentConfig : productionConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment