Created
February 19, 2019 09:31
-
-
Save adeelibr/55eec6bef2e5251962caeb9c1afbf7a6 to your computer and use it in GitHub Desktop.
Webpack configuration [CT 2-19-2019]
This file contains hidden or 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
/* eslint-disable*/ | |
const merge = require('webpack-merge'); | |
const baseConfig = require('./base.config'); | |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
const WebpackVisualizer = require('webpack-visualizer-plugin'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const productionConfig = env => { | |
return merge([ | |
{ | |
optimization: { | |
minimizer: [new UglifyJsPlugin()], | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin(), | |
new OptimizeCssAssetsPlugin(), | |
new WebpackVisualizer({ filename: './statistics_visual.html' }), | |
], | |
}, | |
]); | |
}; | |
module.exports = env => { | |
return merge(baseConfig(env), productionConfig(env)); | |
}; |
This file contains hidden or 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
/* eslint-disable*/ | |
const webpack = require('webpack'); | |
const path = require('path'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const merge = require('webpack-merge'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const APP_DIR = path.resolve(__dirname, '../src'); | |
module.exports = env => { | |
const { PLATFORM, VERSION } = env; | |
return merge([ | |
{ | |
entry: ['@babel/polyfill', APP_DIR], | |
devtool: 'source-map', | |
module: { | |
rules: [ | |
{ | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
}, | |
}, | |
{ | |
test: /\.(scss|css)$/, | |
use: [ | |
PLATFORM === 'production' ? MiniCssExtractPlugin.loader : 'style-loader', | |
'css-loader', | |
'sass-loader', | |
], | |
}, | |
{ | |
test: /\.svg$/, | |
use: [ | |
{ | |
loader: "babel-loader" | |
}, | |
{ | |
loader: "react-svg-loader", | |
options: { | |
jsx: true // true outputs JSX tags | |
} | |
} | |
] | |
}, | |
], | |
}, | |
plugins: [ | |
new CopyWebpackPlugin([{ from: 'src/static' }]), | |
new HtmlWebpackPlugin({ | |
template: './src/index.html', | |
filename: 'index.html', | |
}), | |
new webpack.DefinePlugin({ | |
'process.env.VERSION': JSON.stringify(VERSION), | |
'process.env.PLATFORM': JSON.stringify(PLATFORM), | |
}), | |
], | |
}, | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment