Skip to content

Instantly share code, notes, and snippets.

@vladhd93
Last active December 1, 2017 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladhd93/5d82af3feb80a5a3d8fc16f6ab27bcba to your computer and use it in GitHub Desktop.
Save vladhd93/5d82af3feb80a5a3d8fc16f6ab27bcba to your computer and use it in GitHub Desktop.
const webpack = require('webpack');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
require('babel-polyfill');
const extractCommons = new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons.js',
minChunks:2
});
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('[name].css');
const config = {
context: __dirname,
entry: {
app: './apps/utils/react/app.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
modules: ['node_modules', 'apps/utils/react'],
extensions: ['.js', '.jsx', '.json'],
alias: {
'common-scss': path.resolve(__dirname, 'apps/utils/react/scss'),
countries: path.resolve(__dirname, 'countries.json'),
},
},
module: {
rules: [
{
test: /\.svg$/,
loader: 'svg-url-loader',
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.js$/,
exclude: /node_modules(?!\/webpack-dev-server)/,
include: __dirname,
use: [
{
loader: 'babel-loader',
options: {
presets: [['env', { modules: false }]],
},
},
],
},
{
test: /\.(png|jpg)$/,
use: [
{
loader: 'url-loader',
options: { limit: 10000 }, // Convert images < 10k to base64 strings
},
],
},
{
test: /\.scss|css$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].css',
context: './',
outputPath: '',
publicPath: './',
},
},
{ loader: 'autoprefixer-loader' },
{
loader: 'extract-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
minimize: true,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
],
},
plugins: [extractCommons, extractCSS,new UglifyJsPlugin({
test: /\.js($|\?)/i,
sourceMap: true,
uglifyOptions: {
compress: true
}
})],
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment