diff --git a/.browserslistrc b/.browserslistrc index 35d4c96..64e7ec0 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -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 diff --git a/config/build/buildPlugins.ts b/config/build/buildPlugins.ts index 6aeef70..3da6ad9 100644 --- a/config/build/buildPlugins.ts +++ b/config/build/buildPlugins.ts @@ -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, @@ -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, @@ -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; } diff --git a/config/build/buildWebpackConfig.ts b/config/build/buildWebpackConfig.ts index 7adb72e..6d8355e 100644 --- a/config/build/buildWebpackConfig.ts +++ b/config/build/buildWebpackConfig.ts @@ -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, }; } diff --git a/config/build/loaders/buildBabelLoader.ts b/config/build/loaders/buildBabelLoader.ts index 7f9ac1c..2fda218 100644 --- a/config/build/loaders/buildBabelLoader.ts +++ b/config/build/loaders/buildBabelLoader.ts @@ -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'] }, ], diff --git a/config/build/loaders/buildCssLoader.ts b/config/build/loaders/buildCssLoader.ts index 8c5f707..210d9e0 100644 --- a/config/build/loaders/buildCssLoader.ts +++ b/config/build/loaders/buildCssLoader.ts @@ -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, { diff --git a/package.json b/package.json index 89cfab9..5bc350b 100644 --- a/package.json +++ b/package.json @@ -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": "", diff --git a/scripts/clear-cache.js b/scripts/clear-cache.js new file mode 100644 index 0000000..41792ff --- /dev/null +++ b/scripts/clear-cache.js @@ -0,0 +1,4 @@ +// path/fs +console.log('CLEAR CACHE'); +// to delete cache in node_modules +// rmdir /s /q .\\node_modules\\.cache