Skip to content

Commit

Permalink
remove webpack.config.js, create two separate configs for production …
Browse files Browse the repository at this point in the history
…and development
  • Loading branch information
drillprop committed Dec 4, 2019
1 parent 02a4210 commit f9d51fb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
22 changes: 8 additions & 14 deletions webpack.config.js → webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: 'src/index.js',
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
publicPath: './'
filename: 'main.js'
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader'
test: /\.m?js$/,
exclude: /(node_modules)/,
loader: 'babel-loader'
},
{
test: /\.(png|svg|jpg|gif)$/,
use: 'file-loader'
test: /\.(png|jpe?g|gif)$/,
use: ['file-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html'
})
],
mode: 'development',
devServer: {
historyApiFallback: true,
overlay: true,
stats: 'minimal'
}
]
};
12 changes: 12 additions & 0 deletions webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const common = require('./webpack.common');
const webpackMerge = require('webpack-merge');

module.exports = webpackMerge(common, {
mode: 'development',
devServer: {
historyApiFallback: true,
overlay: true
},
stats: 'minimal',
devtool: 'cheap-module-eval-source-map'
});
44 changes: 44 additions & 0 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const common = require('./webpack.common');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpackMerge = require('webpack-merge');

module.exports = webpackMerge(common, {
mode: 'production',
optimization: {
minimize: true
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }]
},
{
test: /\.(png|jpe?g|gif)$/,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65
}
}
}
]
}
]
},
plugins: [new CleanWebpackPlugin()]
});

0 comments on commit f9d51fb

Please sign in to comment.