Skip to content

Commit

Permalink
feat: update webpack config for builds optimization, add postinstall …
Browse files Browse the repository at this point in the history
…script
  • Loading branch information
TomatoVan committed Mar 20, 2024
1 parent 26da0bb commit 4300c85
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
8 changes: 7 additions & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Browsers that we support
[production]
defaults
not IE 11


[development]
last 2 Chrome versions
last 2 Firefox versions
last 1 Safari version
17 changes: 12 additions & 5 deletions config/build/buildPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BuildOptions } from './types/config';
export function buildPlugins({
paths, isDev, apiUrl, project,
}: BuildOptions): webpack.WebpackPluginInstance[] {
const isProd = !isDev;
const plugins = [
new HtmlWebpackPlugin({
template: paths.html,
Expand All @@ -25,11 +26,6 @@ export function buildPlugins({
__API__: JSON.stringify(apiUrl),
__PROJECT__: JSON.stringify(project),
}),
new CopyPlugin({
patterns: [
{ from: paths.locales, to: paths.buildLocales },
],
}),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
Expand All @@ -52,6 +48,17 @@ export function buildPlugins({
openAnalyzer: false,
}));
}
if (isProd) {
plugins.push(new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css',
chunkFilename: 'css/[name].[contenthash:8].css',
}));
plugins.push(new CopyPlugin({
patterns: [
{ from: paths.locales, to: paths.buildLocales },
],
}));
}

return plugins;
}
2 changes: 1 addition & 1 deletion config/build/buildWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function buildWebpackConfig(options: BuildOptions): webpack.Configuration
rules: buildLoaders(options),
},
resolve: buildResolvers(options),
devtool: isDev ? 'inline-source-map' : undefined,
devtool: isDev ? 'eval-cheap-module-source-map' : undefined,
devServer: isDev ? buildDevServer(options) : undefined,
};
}
11 changes: 3 additions & 8 deletions config/build/loaders/buildBabelLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ interface BuildBabelLoaderProps extends BuildOptions {
}

export function buildBabelLoader({ isDev, isTsx }: BuildBabelLoaderProps) {
const isProd = !isDev;
return {
test: isTsx ? /\.(jsx|tsx)$/ : /\.(js|ts)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['@babel/preset-env'],
plugins: [
[
'i18next-extract',
{
locales: ['ru', 'en'],
keyAsDefaultValue: true,
},
],
['@babel/plugin-transform-typescript', { isTsx }],
'@babel/plugin-transform-runtime',
isTsx && [
isTsx && isProd && [
babelRemovePropsPlugin,
{ props: ['data-testid'] },
],
Expand Down
1 change: 1 addition & 0 deletions config/build/loaders/buildCssLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
export function buildCssLoader(isDev: boolean) {
return {
test: /\.s[ac]ss$/i,
exclude: /node_modules/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"test:ui:html": "reg-cli --from .loki/report.json --report .loki/report.html",
"storybook": "start-storybook -p 6006 -c ./config/storybook",
"storybook:build": "build-storybook -c ./config/storybook",
"generate:slice": "node ./scripts/createSlice/index.js"
"generate:slice": "node ./scripts/createSlice/index.js",
"postinstall": "node ./scripts/clear-cache.js"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 4 additions & 0 deletions scripts/clear-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// path/fs
console.log('CLEAR CACHE');
// to delete cache in node_modules
// rmdir /s /q .\\node_modules\\.cache

0 comments on commit 4300c85

Please sign in to comment.