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')
|
2022-09-22 22:29:29 +03:00
|
|
|
const { DefinePlugin } = require('webpack')
|
|
|
|
|
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: {
|
|
|
|
plugins: ['@vanilla-extract/babel-plugin'],
|
2023-03-27 19:48:02 +03:00
|
|
|
env: {
|
|
|
|
test: {
|
|
|
|
plugins: ['istanbul'],
|
|
|
|
},
|
|
|
|
development: {
|
|
|
|
plugins: ['istanbul'],
|
|
|
|
},
|
|
|
|
},
|
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/',
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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, {
|
|
|
|
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-17 19:28:00 +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-17 19:28:00 +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-17 19:28:00 +03:00
|
|
|
return plugin
|
|
|
|
})
|
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'
|
|
|
|
|
2022-08-11 02:38:23 +03:00
|
|
|
return webpackConfig
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|