Skip to content

Instantly share code, notes, and snippets.

@LANSELOT
Created May 11, 2020 08:27
Show Gist options
  • Save LANSELOT/3a2c9371754248acd4092957c67bf8fb to your computer and use it in GitHub Desktop.
Save LANSELOT/3a2c9371754248acd4092957c67bf8fb to your computer and use it in GitHub Desktop.
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = function (env) {
env = env || {};
var isProd = env.NODE_ENV === 'production';
// Setup base config for all environments
var config = {
entry: {
app: './Client/js/main',
appAdmin: './Areas/Admin/Client/js/main'
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'wwwroot/dist')
},
devtool: 'eval-source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
plugins: [
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),
new MiniCssExtractPlugin()
],
module: {
rules: [
{ test: /\.css?$/, use:
[
MiniCssExtractPlugin.loader, // instead of style-loader
'css-loader'
] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{ test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }
]
}
}
// Alter config for prod environment
if (isProd) {
config.devtool = 'source-map';
config.plugins = config.plugins.concat([
new UglifyJsPlugin({
cache: true,
})
]);
}
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment