2023-04-10 20:05:22 +03:00
|
|
|
/* eslint-env node */
|
2022-08-11 02:38:23 +03:00
|
|
|
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin')
|
2023-04-13 22:43:47 +03:00
|
|
|
const { execSync } = require('child_process')
|
2022-08-11 02:38:23 +03:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2023-04-21 00:12:43 +03:00
|
|
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
|
|
|
const { DefinePlugin, IgnorePlugin } = require('webpack')
|
2022-09-22 22:29:29 +03:00
|
|
|
|
2023-04-13 22:43:47 +03:00
|
|
|
const commitHash = execSync('git rev-parse HEAD').toString().trim()
|
2023-04-17 19:28:00 +03:00
|
|
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
|
|
|
|
|
|
// Linting and type checking are only necessary as part of development and testing.
|
|
|
|
// Omit them from production builds, as they slow down the feedback loop.
|
|
|
|
const shouldLintOrTypeCheck = !isProduction
|
2022-08-11 02:38:23 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
babel: {
|
2023-04-21 01:34:09 +03:00
|
|
|
plugins: [
|
|
|
|
'@vanilla-extract/babel-plugin',
|
|
|
|
...(process.env.REACT_APP_ADD_COVERAGE_INSTRUMENTATION
|
|
|
|
? [
|
|
|
|
[
|
|
|
|
'istanbul',
|
|
|
|
{
|
|
|
|
all: true,
|
|
|
|
include: ['src/**/*.tsx', 'src/**/*.ts'],
|
|
|
|
exclude: [
|
|
|
|
'src/**/*.css',
|
|
|
|
'src/**/*.css.ts',
|
|
|
|
'src/**/*.test.ts',
|
|
|
|
'src/**/*.test.tsx',
|
|
|
|
'src/**/*.spec.ts',
|
|
|
|
'src/**/*.spec.tsx',
|
|
|
|
'src/**/graphql/**/*',
|
|
|
|
'src/**/*.d.ts',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]
|
|
|
|
: []),
|
|
|
|
],
|
2023-01-10 00:54:48 +03:00
|
|
|
},
|
2023-04-17 19:28:00 +03:00
|
|
|
eslint: {
|
|
|
|
enable: shouldLintOrTypeCheck,
|
|
|
|
pluginOptions(eslintConfig) {
|
|
|
|
return Object.assign(eslintConfig, {
|
|
|
|
cache: true,
|
|
|
|
cacheLocation: 'node_modules/.cache/eslint/',
|
2023-04-20 23:44:57 +03:00
|
|
|
ignorePath: '.gitignore',
|
2023-04-17 19:28:00 +03:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
typescript: {
|
|
|
|
enableTypeChecking: shouldLintOrTypeCheck,
|
|
|
|
},
|
2023-01-10 00:54:48 +03:00
|
|
|
jest: {
|
|
|
|
configure(jestConfig) {
|
2023-04-17 19:28:00 +03:00
|
|
|
return Object.assign(jestConfig, {
|
2023-04-25 22:06:58 +03:00
|
|
|
transform: {
|
|
|
|
'\\.css\\.ts$': './vanilla.transform.cjs',
|
|
|
|
...jestConfig.transform,
|
|
|
|
},
|
2023-04-17 19:28:00 +03:00
|
|
|
cacheDirectory: 'node_modules/.cache/jest',
|
2023-01-26 01:12:23 +03:00
|
|
|
transformIgnorePatterns: ['@uniswap/conedison/format', '@uniswap/conedison/provider'],
|
2023-01-10 00:54:48 +03:00
|
|
|
moduleNameMapper: {
|
|
|
|
'@uniswap/conedison/format': '@uniswap/conedison/dist/format',
|
2023-01-26 01:12:23 +03:00
|
|
|
'@uniswap/conedison/provider': '@uniswap/conedison/dist/provider',
|
2023-01-10 00:54:48 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-08-11 02:38:23 +03:00
|
|
|
},
|
|
|
|
webpack: {
|
2023-04-13 22:43:47 +03:00
|
|
|
plugins: [new VanillaExtractPlugin({ identifiers: 'short' })],
|
2022-08-11 02:38:23 +03:00
|
|
|
configure: (webpackConfig) => {
|
2023-04-21 00:12:43 +03:00
|
|
|
webpackConfig.plugins = webpackConfig.plugins
|
|
|
|
.map((plugin) => {
|
|
|
|
// Extend process.env with dynamic values (eg commit hash).
|
|
|
|
// This will make dynamic values available to JavaScript only, not to interpolated HTML (ie index.html).
|
|
|
|
if (plugin instanceof DefinePlugin) {
|
|
|
|
Object.assign(plugin.definitions['process.env'], {
|
|
|
|
REACT_APP_GIT_COMMIT_HASH: JSON.stringify(commitHash),
|
|
|
|
})
|
|
|
|
}
|
2022-11-17 21:59:40 +03:00
|
|
|
|
2023-04-21 00:12:43 +03:00
|
|
|
// CSS ordering is mitigated through scoping / naming conventions, so we can ignore order warnings.
|
|
|
|
// See https://webpack.js.org/plugins/mini-css-extract-plugin/#remove-order-warnings.
|
|
|
|
if (plugin instanceof MiniCssExtractPlugin) {
|
|
|
|
plugin.options.ignoreOrder = true
|
|
|
|
}
|
2023-04-13 22:43:47 +03:00
|
|
|
|
2023-04-21 00:12:43 +03:00
|
|
|
return plugin
|
|
|
|
})
|
|
|
|
.filter((plugin) => {
|
|
|
|
// Case sensitive paths are enforced by TypeScript.
|
|
|
|
// See https://www.typescriptlang.org/tsconfig#forceConsistentCasingInFileNames.
|
|
|
|
if (plugin instanceof CaseSensitivePathsPlugin) return false
|
|
|
|
|
|
|
|
// IgnorePlugin is used to tree-shake moment locales, but we do not use moment in this project.
|
|
|
|
if (plugin instanceof IgnorePlugin) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
})
|
2023-04-13 22:43:47 +03:00
|
|
|
|
|
|
|
// We're currently on Webpack 4.x which doesn't support the `exports` field in package.json.
|
|
|
|
// Instead, we need to manually map the import path to the correct exports path (eg dist or build folder).
|
2022-11-17 21:59:40 +03:00
|
|
|
// See https://github.com/webpack/webpack/issues/9509.
|
|
|
|
webpackConfig.resolve.alias['@uniswap/conedison'] = '@uniswap/conedison/dist'
|
|
|
|
|
2023-05-02 18:46:32 +03:00
|
|
|
// Configure webpack optimization:
|
|
|
|
webpackConfig.optimization.splitChunks = Object.assign(webpackConfig.optimization.splitChunks, {
|
|
|
|
// Cap the chunk size to 5MB.
|
|
|
|
// react-scripts suggests a chunk size under 1MB after gzip, but we can only measure maxSize before gzip.
|
|
|
|
// react-scripts also caps cacheable chunks at 5MB, which gzips to below 1MB, so we cap chunk size there.
|
|
|
|
// See https://github.com/facebook/create-react-app/blob/d960b9e/packages/react-scripts/config/webpack.config.js#L713-L716.
|
|
|
|
maxSize: 5 * 1024 * 1024,
|
|
|
|
})
|
|
|
|
|
2022-08-11 02:38:23 +03:00
|
|
|
return webpackConfig
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|