2021-02-21 06:02:06 +05:30
|
|
|
// shared config (dev and prod)
|
2021-10-27 15:54:12 +08:00
|
|
|
import CompressionPlugin from 'compression-webpack-plugin';
|
|
|
|
|
import CopyPlugin from 'copy-webpack-plugin';
|
|
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
|
import { resolve } from 'path';
|
|
|
|
|
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
|
2021-11-16 21:13:20 +05:30
|
|
|
import webpack, { WebpackPluginInstance } from 'webpack';
|
2021-02-21 06:02:06 +05:30
|
|
|
|
2021-10-27 15:54:12 +08:00
|
|
|
const __dirname = resolve();
|
|
|
|
|
|
|
|
|
|
const config: webpack.Configuration = {
|
2021-08-26 11:50:47 +05:30
|
|
|
mode: 'production',
|
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
entry: resolve(__dirname, './src/index.tsx'),
|
2021-02-21 06:23:56 +05:30
|
|
|
output: {
|
2021-11-16 21:13:20 +05:30
|
|
|
filename: ({ chunk }): string => {
|
2021-10-27 15:54:12 +08:00
|
|
|
const hash = chunk?.hash;
|
|
|
|
|
const name = chunk?.name;
|
2021-08-23 11:38:25 +05:30
|
|
|
return `js/${name}-${hash}.js`;
|
|
|
|
|
},
|
2021-08-26 11:50:47 +05:30
|
|
|
path: resolve(__dirname, './build'),
|
|
|
|
|
publicPath: '/',
|
2021-02-21 06:23:56 +05:30
|
|
|
},
|
2021-02-21 06:02:06 +05:30
|
|
|
|
2021-02-21 06:23:56 +05:30
|
|
|
resolve: {
|
2021-08-26 11:50:47 +05:30
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
2021-08-19 22:53:33 +05:30
|
|
|
plugins: [new TsconfigPathsPlugin({})],
|
2021-02-21 06:23:56 +05:30
|
|
|
},
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
2021-11-22 12:59:32 +05:30
|
|
|
test: [/\.jsx?$/, /\.tsx?$/],
|
2021-08-26 11:50:47 +05:30
|
|
|
use: ['babel-loader'],
|
2021-02-21 06:23:56 +05:30
|
|
|
exclude: /node_modules/,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
2021-08-26 11:50:47 +05:30
|
|
|
use: ['style-loader', 'css-loader'],
|
2021-02-21 06:23:56 +05:30
|
|
|
},
|
2021-11-22 12:59:32 +05:30
|
|
|
{
|
|
|
|
|
test: /\.(scss|sass)$/,
|
|
|
|
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
|
|
|
},
|
2021-02-21 06:23:56 +05:30
|
|
|
{
|
|
|
|
|
test: /\.(jpe?g|png|gif|svg)$/i,
|
|
|
|
|
use: [
|
2021-08-26 11:50:47 +05:30
|
|
|
'file-loader?hash=sha512&digest=hex&name=img/[chunkhash].[ext]',
|
|
|
|
|
'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false',
|
2021-02-21 06:23:56 +05:30
|
|
|
],
|
|
|
|
|
},
|
2021-11-22 11:49:09 +05:30
|
|
|
{
|
|
|
|
|
test: /\.(ttf|eot|woff|woff2)$/,
|
|
|
|
|
use: ['file-loader'],
|
|
|
|
|
},
|
2021-02-21 06:23:56 +05:30
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
2021-10-27 15:54:12 +08:00
|
|
|
new HtmlWebpackPlugin({ template: 'src/index.html.ejs' }),
|
2021-11-16 21:13:20 +05:30
|
|
|
(new CompressionPlugin({
|
2021-07-29 17:35:43 +05:30
|
|
|
exclude: /.map$/,
|
2021-11-16 21:13:20 +05:30
|
|
|
}) as unknown) as WebpackPluginInstance,
|
|
|
|
|
(new CopyPlugin({
|
2021-08-26 11:50:47 +05:30
|
|
|
patterns: [{ from: resolve(__dirname, 'public/'), to: '.' }],
|
2021-11-16 21:13:20 +05:30
|
|
|
}) as unknown) as WebpackPluginInstance,
|
2021-07-30 11:47:58 +05:30
|
|
|
new webpack.ProvidePlugin({
|
2021-08-26 11:50:47 +05:30
|
|
|
process: 'process/browser',
|
2021-07-30 11:47:58 +05:30
|
|
|
}),
|
|
|
|
|
new webpack.DefinePlugin({
|
2021-08-26 11:50:47 +05:30
|
|
|
'process.env': JSON.stringify(process.env),
|
2021-07-30 11:47:58 +05:30
|
|
|
}),
|
2021-02-21 06:23:56 +05:30
|
|
|
],
|
|
|
|
|
performance: {
|
|
|
|
|
hints: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-10-27 15:54:12 +08:00
|
|
|
|
2021-11-16 21:13:20 +05:30
|
|
|
export default config;
|