-
-
Save tridungle/f4c8babf6b61a403a89a3a7905592621 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