Last active
March 9, 2018 14:49
-
-
Save whois42/fbb3a49efe9f1a84b92c49c5779a75f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var CleanWebpackPlugin = require('clean-webpack-plugin'); | |
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
var UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | |
var ENV = process.env.npm_lifecycle_event; | |
var isProd = ENV === 'build'; | |
var isDev = ENV === 'dev'; | |
module.exports = function makeConfig() { | |
var configuration = { | |
entry: ['./src/index.js'], | |
output: { | |
path: __dirname + '/dist', | |
publicPath: '/', | |
filename: isProd ? 'index.[hash].js' : 'index.bundle.js' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
use: ['babel-loader'] | |
}, | |
{ | |
test: /\.(scss|sass)$/, | |
use: ExtractTextPlugin.extract({ | |
fallback: 'style-loader', | |
use: [ | |
{loader: 'css-loader', query: { | |
sourceMap: true, | |
modules: true, | |
import: true}}, | |
{loader: 'sass-loader'} | |
] | |
}) | |
}, | |
{ | |
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/, | |
loader: 'file-loader' | |
} | |
] | |
}, | |
plugins: [new ExtractTextPlugin({filename: 'frame_styles.css', disable: !isProd, allChunks: true})], | |
resolve: { | |
extensions: ['*', '.js', '.jsx'] | |
} | |
} | |
if(isProd) { | |
configuration.plugins.concat([ | |
new CleanWebpackPlugin(['dist'], { | |
verbose: true | |
}), | |
new webpack.NoEmitOnErrorsPlugin(), | |
new UglifyJSPlugin() | |
]); | |
configuration.devtool = 'source-map'; | |
} else if(isDev) { | |
configuration.plugins.concat([ | |
new CleanWebpackPlugin(['dist'], { | |
verbose: true, | |
exclude: ['index.html'] | |
}) | |
]); | |
configuration.devtool = 'inline-source-map'; | |
} | |
return configuration; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment