Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
dotenv, build:analyze, postcss-normalize, postcss-preset-env, pollyfi…
Browse files Browse the repository at this point in the history
…ll using core-js and lot more improvements
  • Loading branch information
dhinesh03 committed Oct 31, 2019
1 parent 12396d2 commit f40812f
Show file tree
Hide file tree
Showing 21 changed files with 2,722 additions and 1,031 deletions.
Empty file added .env
Empty file.
Empty file added .env.development
Empty file.
28 changes: 28 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function(api) {
api.cache(false);
const presets = [
[
'@babel/preset-env',
{
useBuiltIns: 'entry',
corejs: { version: '3.3' }
//debug: true
}
]
];

let plugins = [
[
'transform-react-jsx',
{
pragma: 'm'
}
],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-runtime'
];
return {
presets,
plugins
};
};
11 changes: 11 additions & 0 deletions config/webpack/addons/webpack.bundleanalyze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const WebpackBundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const paths = require('../paths');
module.exports = {
plugins: [
new WebpackBundleAnalyzer({
analyzerMode: 'static',
reportFilename: paths.bundleReportPath,
openAnalyzer: false
})
]
};
7 changes: 7 additions & 0 deletions config/webpack/addons/webpack.bundlevisualizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Visualizer = require('webpack-visualizer-plugin');

module.exports = {
plugins: [
new Visualizer()
]
};
11 changes: 11 additions & 0 deletions config/webpack/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { resolve } = require('path');

module.exports = {
contextPath: resolve(__dirname, '../', '../', 'src'),
outputPath: resolve(__dirname, '../', '../', 'dist'),
bundleReportPath: resolve(__dirname, '../', '../', 'dist', 'report.html'),
entryPath: resolve(__dirname, '../', '../', 'src/index.js'),
templatePath: resolve(__dirname, '../', '../', 'src/index.html'),
envDevPath: resolve(__dirname, '../', '../', '.env.development'),
envPath: resolve(__dirname, '../', '../', '.env')
};
81 changes: 81 additions & 0 deletions config/webpack/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const postcssNormalize = require('postcss-normalize');
const imageInlineSizeLimit = 10000;
const fontInlineSizeLimit = 10000;

module.exports = [
{
test: /\.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'url-loader',
options: {
limit: fontInlineSizeLimit,
name: '[name].[ext]',
publicPath: '../fonts/',
outputPath: 'fonts/'
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
// if hmr does not work, this is a forceful method.
reloadAll: process.env.NODE_ENV === 'development'
}
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
}),
postcssNormalize()
]
}
},
{
loader: 'sass-loader'
}
]
},
{
test: /\.(jpe?g|png|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: imageInlineSizeLimit,
name: '[name].[hash:8].[ext]',
publicPath: '../images/',
outputPath: 'images/'
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
limit: 1000,
name: '[name].[hash:8].[ext]',
publicPath: '../images/',
outputPath: 'images/'
}
}
];
26 changes: 26 additions & 0 deletions config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const paths = require('./paths');
const rules = require('./rules');

module.exports = {
context: paths.contextPath,
entry: {
main: paths.entryPath,
},
module: {
rules
},
resolve: {
modules: ['src', 'node_modules'],
extensions: ['*', '.js', '.scss', '.css']
},
plugins: [
new HtmlWebpackPlugin({
template: paths.templatePath,
}),
new webpack.ProvidePlugin({
m: 'mithril' //Global access
}),
]
};
59 changes: 28 additions & 31 deletions webpack.dev.js → config/webpack/webpack.development.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const Dotenv = require('dotenv-webpack');
const paths = require('./paths');

const common = require('./webpack.common.js');

module.exports = merge(common, {
module.exports = {
mode: 'development',
devtool: 'source-map',
devtool: 'cheap-module-source-map',
devServer: {
hot: true,
contentBase: './dist',
contentBase: paths.outputPath,
port: 3000,
proxy: {
'/api': 'http://localhost:3001',
'/api': 'http://localhost:3001'
},
open: true,
/*overlay: {
errors: true,
warnings: true,
},*/
compress: true,
historyApiFallback: true
},
module: {
rules: [{
test: /\.(sa|sc|c)ss$/,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: true,
// if hmr does not work, this is a forceful method.
reloadAll: true,
},
}, {
loader: 'css-loader',
options: { sourceMap: true },
}, {
loader: 'postcss-loader',
}, {
loader: 'sass-loader',
options: { sourceMap: true },
}],
}, {
test: /\.js$/,
enforce: 'pre',
exclude: /node_modules/,
Expand All @@ -52,15 +36,28 @@ module.exports = merge(common, {
failOnError: false,
// Toggle autofix
fix: false,
formatter: require('eslint/lib/cli-engine/formatters/stylish'),
},
}],
formatter: require('eslint/lib/cli-engine/formatters/stylish')
}
}]
},
output: {
path: paths.outputPath,
filename: 'js/[name].js',
chunkFilename: 'js/[name].js'
},
plugins: [
new Dotenv({
path: paths.envDevPath // Path to .env file (this is the default)
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[id].css',
chunkFilename: 'css/[id].css'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.HotModuleReplacementPlugin()
],
});
optimization: {
splitChunks: {
chunks: 'all'
}
}
};
52 changes: 52 additions & 0 deletions config/webpack/webpack.production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const paths = require('./paths');

module.exports = {
mode: 'production',
devtool: 'source-map',
output: {
path: paths.outputPath,
filename: 'js/[name]-[contenthash:8].js',
chunkFilename: 'js/[name]-[contenthash:8].js'
},
plugins: [
new webpack.HashedModuleIdsPlugin(), // so that file hashes don't change unexpectedly
new CleanWebpackPlugin(),
new Dotenv({
path: paths.envPath // Path to .env file (this is the default)
}),
new MiniCssExtractPlugin({
filename: 'css/[name]-[contenthash:8].css',
chunkFilename: 'css/[id]-[contenthash:8].css'
})
],
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 30000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];

// npm package names are URL-safe, but some servers don't like @ symbols
return `vendor.${packageName.replace('@', '')}`;
}
}
}
},
minimizer: [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})]
}
};
Loading

0 comments on commit f40812f

Please sign in to comment.