diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000000..5a36444b641 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +packages/**/dist/*.js +packages/**/config/*.js +**/node_modules \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..81a61fc6598 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,119 @@ +'use strict'; + +const restrictedGlobals = require('confusing-browser-globals'); + +const OFF = 0; +const ERROR = 2 + +module.exports = { + extends: ['fbjs', 'prettier'], + + // Stop ESLint from looking for a configuration file in parent folders + root: true, + + plugins: [ + 'jest', + 'no-for-of-loops', + 'no-function-declare-after-return', + 'react', + ], + + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 8, + sourceType: 'script', + ecmaFeatures: { + experimentalObjectRestSpread: true, + }, + }, + // We're stricter than the default config, mostly. We'll override a few rules + // and then enable some React specific ones. + rules: { + 'accessor-pairs': OFF, + 'brace-style': [ERROR, '1tbs'], + 'consistent-return': OFF, + 'dot-location': [ERROR, 'property'], + // We use console['error']() as a signal to not transform it: + 'dot-notation': [ERROR, {allowPattern: '^(error|warn)$'}], + 'eol-last': ERROR, + eqeqeq: [ERROR, 'allow-null'], + indent: OFF, + 'jsx-quotes': [ERROR, 'prefer-double'], + 'keyword-spacing': [ERROR, {after: true, before: true}], + 'no-bitwise': OFF, + 'no-console': OFF, + 'no-inner-declarations': [ERROR, 'functions'], + 'no-multi-spaces': ERROR, + 'no-restricted-globals': [ERROR].concat(restrictedGlobals), + 'no-restricted-syntax': [ERROR, 'WithStatement'], + 'no-shadow': ERROR, + 'no-unused-expressions': ERROR, + 'no-unused-vars': [ERROR, {args: 'none'}], + 'no-use-before-define': OFF, + 'no-useless-concat': OFF, + quotes: [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true}], + 'space-before-blocks': ERROR, + 'space-before-function-paren': OFF, + 'valid-typeof': [ERROR, {requireStringLiterals: true}], + // Flow fails with with non-string literal keys + 'no-useless-computed-key': OFF, + + // We apply these settings to files that should run on Node. + // They can't use JSX or ES6 modules, and must be in strict mode. + // They can, however, use other ES6 features. + // (Note these rules are overridden later for source files.) + 'no-var': ERROR, + strict: ERROR, + + // Enforced by Prettier + // TODO: Prettier doesn't handle long strings or long comments. Not a big + // deal. But I turned it off because loading the plugin causes some obscure + // syntax error and it didn't seem worth investigating. + 'max-len': OFF, + // Prettier forces semicolons in a few places + 'flowtype/object-type-delimiter': OFF, + + // React & JSX + // Our transforms set this automatically + 'react/jsx-boolean-value': [ERROR, 'always'], + 'react/jsx-no-undef': ERROR, + // We don't care to do this + 'react/jsx-sort-prop-types': OFF, + 'react/jsx-space-before-closing': ERROR, + 'react/jsx-uses-react': ERROR, + 'react/no-is-mounted': OFF, + // This isn't useful in our test code + 'react/react-in-jsx-scope': ERROR, + 'react/self-closing-comp': ERROR, + // We don't care to do this + 'react/jsx-wrap-multilines': [ + ERROR, + {declaration: false, assignment: false}, + ], + + // Prevent for...of loops because they require a Symbol polyfill. + // You can disable this rule for code that isn't shipped (e.g. build scripts and tests). + 'no-for-of-loops/no-for-of-loops': ERROR, + + // Prevent function declarations after return statements + 'no-function-declare-after-return/no-function-declare-after-return': ERROR, + }, + + overrides: [ + { + // We apply these settings to the source files that get compiled. + // They can use all features including JSX (but shouldn't use `var`). + files: 'packages/*/src/**/*.js', + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 8, + sourceType: 'module', + }, + rules: { + 'no-var': ERROR, + 'prefer-const': ERROR, + strict: OFF, + }, + }, + ], +}; diff --git a/.gitignore b/.gitignore index 4d29575de80..fc898890186 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,9 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules +node_modules /.pnp .pnp.js -# testing -/coverage - -# production -/build - -# misc +build +dist .DS_Store .env.local .env.development.local diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000000..5fdf912d18b --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + bracketSpacing: false, + singleQuote: true, + jsxBracketSameLine: true, + trailingComma: 'es5', + printWidth: 80, + parser: 'babel', + trailingComma: 'all', +}; \ No newline at end of file diff --git a/README.md b/README.md index 9c40dcdc3d8..aa196e79741 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,3 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +# Outline JS -## Available Scripts - -In the project directory, you can run: - -### `yarn start` - -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.
-You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting - -### Analyzing the Bundle Size - -This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size - -### Making a Progressive Web App - -This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app - -### Advanced Configuration - -This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration - -### Deployment - -This section has moved here: https://facebook.github.io/create-react-app/docs/deployment - -### `yarn build` fails to minify - -This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify +Outline is a fast, lightweight, rich-text editor library for React. \ No newline at end of file diff --git a/package.json b/package.json index 397bed62522..783686c4729 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,38 @@ { - "name": "outline", - "version": "0.1.0", + "name": "outline-example", + "description": "Outline is a fast, lightweight, rich-text editor for React", + "version": "1.0.0", "private": true, - "dependencies": { - "@testing-library/jest-dom": "^4.2.4", - "@testing-library/react": "^9.3.2", - "@testing-library/user-event": "^7.1.2", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-scripts": "4.0.0" - }, + "workspaces": [ + "packages/*" + ], "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": "react-app" + "start": "npm run build && npm start --prefix packages/outline-example", + "build": "node scripts/build.js", + "build-prod": "node scripts/build.js --prod", + "watch": "node scripts/build.js --watch" }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] + "devDependencies": { + "@babel/plugin-transform-flow-strip-types": "^7.12.1", + "@babel/preset-react": "^7.12.5", + "@rollup/plugin-babel": "^5.2.1", + "@rollup/plugin-node-resolve": "^10.0.0", + "confusing-browser-globals": "^1.0.10", + "eslint": "^7.12.1", + "eslint-config-fbjs": "^3.1.1", + "eslint-config-prettier": "^6.15.0", + "eslint-plugin-babel": "^5.3.1", + "eslint-plugin-flowtype": "^5.2.0", + "eslint-plugin-jest": "^24.1.0", + "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-no-for-of-loops": "^1.0.1", + "eslint-plugin-no-function-declare-after-return": "^1.1.0", + "eslint-plugin-react": "^7.21.5", + "flow": "^0.2.3", + "google-closure-compiler": "^20201006.0.0", + "jest": "26.6.0", + "minimist": "^1.2.5", + "prettier": "^2.1.2", + "rollup": "^2.33.1" } } diff --git a/packages/outline-emoji-plugin/package.json b/packages/outline-emoji-plugin/package.json new file mode 100644 index 00000000000..31c9d8c5674 --- /dev/null +++ b/packages/outline-emoji-plugin/package.json @@ -0,0 +1,5 @@ +{ + "name": "outline-emoji-plugin", + "version": "1.0.0", + "main": "dist/index.js" +} diff --git a/src/plugins/EmojiPlugin.js b/packages/outline-emoji-plugin/src/index.js similarity index 53% rename from src/plugins/EmojiPlugin.js rename to packages/outline-emoji-plugin/src/index.js index 05f47cd5bb2..58bfd066c1a 100644 --- a/src/plugins/EmojiPlugin.js +++ b/packages/outline-emoji-plugin/src/index.js @@ -1,36 +1,36 @@ import {useEffect} from 'react'; const baseEmojiStyle = - "background-size: 16px 16px;" + - "height: 16px;" + - "width: 16px;" + - "background-position: center;" + - "background-repeat: no-repeat;" + - "display: inline-block;" + - "margin: 0 1px;" + - "text-align: center;" + - "vertical-align: middle;"; + 'background-size: 16px 16px;' + + 'height: 16px;' + + 'width: 16px;' + + 'background-position: center;' + + 'background-repeat: no-repeat;' + + 'display: inline-block;' + + 'margin: 0 1px;' + + 'text-align: center;' + + 'vertical-align: middle;'; const happySmile = baseEmojiStyle + - "background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t4c/1/16/1f642.png);"; + 'background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t4c/1/16/1f642.png);'; const veryHappySmile = baseEmojiStyle + - "background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t51/1/16/1f603.png);"; + 'background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t51/1/16/1f603.png);'; const unhappySmile = baseEmojiStyle + - "background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/tcb/1/16/1f641.png);"; - const heart = + 'background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/tcb/1/16/1f641.png);'; +const heart = baseEmojiStyle + - "background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t6c/1/16/2764.png);"; + 'background-image: url(https://static.xx.fbcdn.net/images/emoji.php/v9/t6c/1/16/2764.png);'; -const specialSpace = " "; +const specialSpace = ' '; const emojis = { - ":)": happySmile, - ":D": veryHappySmile, - ":(": unhappySmile, - "<3": heart, + ':)': happySmile, + ':D': veryHappySmile, + ':(': unhappySmile, + '<3': heart, }; function textNodeTransform(node, view) { @@ -49,7 +49,7 @@ function textNodeTransform(node, view) { const emojiInline = view .createText(specialSpace) .setStyle(emojiStyle) - .makeImmutable() + .makeImmutable(); targetNode.replace(emojiInline); emojiInline.select(); @@ -62,7 +62,7 @@ function textNodeTransform(node, view) { export function useEmojiPlugin(outlineEditor) { useEffect(() => { if (outlineEditor !== null) { - return outlineEditor.addTextTransform(textNodeTransform) + return outlineEditor.addTextTransform(textNodeTransform); } - }, [outlineEditor]) -} \ No newline at end of file + }, [outlineEditor]); +} diff --git a/packages/outline-example/config/webpack.config.js b/packages/outline-example/config/webpack.config.js new file mode 100644 index 00000000000..dbddb1932d0 --- /dev/null +++ b/packages/outline-example/config/webpack.config.js @@ -0,0 +1,736 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const webpack = require('webpack'); +const resolve = require('resolve'); +const PnpWebpackPlugin = require('pnp-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); +const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin'); +const TerserPlugin = require('terser-webpack-plugin'); +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); +const safePostCssParser = require('postcss-safe-parser'); +const ManifestPlugin = require('webpack-manifest-plugin'); +const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); +const WorkboxWebpackPlugin = require('workbox-webpack-plugin'); +const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); +const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); +const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); +const ESLintPlugin = require('eslint-webpack-plugin'); +const paths = require('./paths'); +const modules = require('./modules'); +const getClientEnvironment = require('./env'); +const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); +const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin'); +const typescriptFormatter = require('react-dev-utils/typescriptFormatter'); +const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); + +const postcssNormalize = require('postcss-normalize'); + +const appPackageJson = require(paths.appPackageJson); + +// Source maps are resource heavy and can cause out of memory issue for large source files. +const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; + +const webpackDevClientEntry = require.resolve( + 'react-dev-utils/webpackHotDevClient' +); +const reactRefreshOverlayEntry = require.resolve( + 'react-dev-utils/refreshOverlayInterop' +); + +// Some apps do not need the benefits of saving a web request, so not inlining the chunk +// makes for a smoother build process. +const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false'; + +const imageInlineSizeLimit = parseInt( + process.env.IMAGE_INLINE_SIZE_LIMIT || '10000' +); + +// Check if TypeScript is setup +const useTypeScript = fs.existsSync(paths.appTsConfig); + +// Get the path to the uncompiled service worker (if it exists). +const swSrc = paths.swSrc; + +// style files regexes +const cssRegex = /\.css$/; +const cssModuleRegex = /\.module\.css$/; +const sassRegex = /\.(scss|sass)$/; +const sassModuleRegex = /\.module\.(scss|sass)$/; + +const hasJsxRuntime = (() => { + if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { + return false; + } + + try { + require.resolve('react/jsx-runtime'); + return true; + } catch (e) { + return false; + } +})(); + +// This is the production and development configuration. +// It is focused on developer experience, fast rebuilds, and a minimal bundle. +module.exports = function (webpackEnv) { + const isEnvDevelopment = webpackEnv === 'development'; + const isEnvProduction = webpackEnv === 'production'; + + // Variable used for enabling profiling in Production + // passed into alias object. Uses a flag if passed into the build command + const isEnvProductionProfile = + isEnvProduction && process.argv.includes('--profile'); + + // We will provide `paths.publicUrlOrPath` to our app + // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. + // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz. + // Get environment variables to inject into our app. + const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1)); + + const shouldUseReactRefresh = env.raw.FAST_REFRESH; + + // common function to get style loaders + const getStyleLoaders = (cssOptions, preProcessor) => { + const loaders = [ + isEnvDevelopment && require.resolve('style-loader'), + isEnvProduction && { + loader: MiniCssExtractPlugin.loader, + // css is located in `static/css`, use '../../' to locate index.html folder + // in production `paths.publicUrlOrPath` can be a relative path + options: paths.publicUrlOrPath.startsWith('.') + ? { publicPath: '../../' } + : {}, + }, + { + loader: require.resolve('css-loader'), + options: cssOptions, + }, + { + // Options for PostCSS as we reference these options twice + // Adds vendor prefixing based on your specified browser support in + // package.json + loader: require.resolve('postcss-loader'), + options: { + // Necessary for external CSS imports to work + // https://github.com/facebook/create-react-app/issues/2677 + ident: 'postcss', + plugins: () => [ + require('postcss-flexbugs-fixes'), + require('postcss-preset-env')({ + autoprefixer: { + flexbox: 'no-2009', + }, + stage: 3, + }), + // Adds PostCSS Normalize as the reset css with default options, + // so that it honors browserslist config in package.json + // which in turn let's users customize the target behavior as per their needs. + postcssNormalize(), + ], + sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, + }, + }, + ].filter(Boolean); + if (preProcessor) { + loaders.push( + { + loader: require.resolve('resolve-url-loader'), + options: { + sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, + root: paths.appSrc, + }, + }, + { + loader: require.resolve(preProcessor), + options: { + sourceMap: true, + }, + } + ); + } + return loaders; + }; + + return { + mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development', + // Stop compilation early in production + bail: isEnvProduction, + devtool: isEnvProduction + ? shouldUseSourceMap + ? 'source-map' + : false + : isEnvDevelopment && 'cheap-module-source-map', + // These are the "entry points" to our application. + // This means they will be the "root" imports that are included in JS bundle. + entry: + isEnvDevelopment && !shouldUseReactRefresh + ? [ + // Include an alternative client for WebpackDevServer. A client's job is to + // connect to WebpackDevServer by a socket and get notified about changes. + // When you save a file, the client will either apply hot updates (in case + // of CSS changes), or refresh the page (in case of JS changes). When you + // make a syntax error, this client will display a syntax error overlay. + // Note: instead of the default WebpackDevServer client, we use a custom one + // to bring better experience for Create React App users. You can replace + // the line below with these two lines if you prefer the stock client: + // + // require.resolve('webpack-dev-server/client') + '?/', + // require.resolve('webpack/hot/dev-server'), + // + // When using the experimental react-refresh integration, + // the webpack plugin takes care of injecting the dev client for us. + webpackDevClientEntry, + // Finally, this is your app's code: + paths.appIndexJs, + // We include the app code last so that if there is a runtime error during + // initialization, it doesn't blow up the WebpackDevServer client, and + // changing JS code would still trigger a refresh. + ] + : paths.appIndexJs, + output: { + // The build folder. + path: isEnvProduction ? paths.appBuild : undefined, + // Add /* filename */ comments to generated require()s in the output. + pathinfo: isEnvDevelopment, + // There will be one main bundle, and one file per asynchronous chunk. + // In development, it does not produce real files. + filename: isEnvProduction + ? 'static/js/[name].[contenthash:8].js' + : isEnvDevelopment && 'static/js/bundle.js', + // TODO: remove this when upgrading to webpack 5 + futureEmitAssets: true, + // There are also additional JS chunk files if you use code splitting. + chunkFilename: isEnvProduction + ? 'static/js/[name].[contenthash:8].chunk.js' + : isEnvDevelopment && 'static/js/[name].chunk.js', + // webpack uses `publicPath` to determine where the app is being served from. + // It requires a trailing slash, or the file assets will get an incorrect path. + // We inferred the "public path" (such as / or /my-project) from homepage. + publicPath: paths.publicUrlOrPath, + // Point sourcemap entries to original disk location (format as URL on Windows) + devtoolModuleFilenameTemplate: isEnvProduction + ? info => + path + .relative(paths.appSrc, info.absoluteResourcePath) + .replace(/\\/g, '/') + : isEnvDevelopment && + (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')), + // Prevents conflicts when multiple webpack runtimes (from different apps) + // are used on the same page. + jsonpFunction: `webpackJsonp${appPackageJson.name}`, + // this defaults to 'window', but by setting it to 'this' then + // module chunks which are built will work in web workers as well. + globalObject: 'this', + }, + optimization: { + minimize: isEnvProduction, + minimizer: [ + // This is only used in production mode + new TerserPlugin({ + terserOptions: { + parse: { + // We want terser to parse ecma 8 code. However, we don't want it + // to apply any minification steps that turns valid ecma 5 code + // into invalid ecma 5 code. This is why the 'compress' and 'output' + // sections only apply transformations that are ecma 5 safe + // https://github.com/facebook/create-react-app/pull/4234 + ecma: 8, + }, + compress: { + ecma: 5, + warnings: false, + // Disabled because of an issue with Uglify breaking seemingly valid code: + // https://github.com/facebook/create-react-app/issues/2376 + // Pending further investigation: + // https://github.com/mishoo/UglifyJS2/issues/2011 + comparisons: false, + // Disabled because of an issue with Terser breaking valid code: + // https://github.com/facebook/create-react-app/issues/5250 + // Pending further investigation: + // https://github.com/terser-js/terser/issues/120 + inline: 2, + }, + mangle: { + safari10: true, + }, + // Added for profiling in devtools + keep_classnames: isEnvProductionProfile, + keep_fnames: isEnvProductionProfile, + output: { + ecma: 5, + comments: false, + // Turned on because emoji and regex is not minified properly using default + // https://github.com/facebook/create-react-app/issues/2488 + ascii_only: true, + }, + }, + sourceMap: shouldUseSourceMap, + }), + // This is only used in production mode + new OptimizeCSSAssetsPlugin({ + cssProcessorOptions: { + parser: safePostCssParser, + map: shouldUseSourceMap + ? { + // `inline: false` forces the sourcemap to be output into a + // separate file + inline: false, + // `annotation: true` appends the sourceMappingURL to the end of + // the css file, helping the browser find the sourcemap + annotation: true, + } + : false, + }, + cssProcessorPluginOptions: { + preset: ['default', { minifyFontValues: { removeQuotes: false } }], + }, + }), + ], + // Automatically split vendor and commons + // https://twitter.com/wSokra/status/969633336732905474 + // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366 + splitChunks: { + chunks: 'all', + name: false, + }, + // Keep the runtime chunk separated to enable long term caching + // https://twitter.com/wSokra/status/969679223278505985 + // https://github.com/facebook/create-react-app/issues/5358 + runtimeChunk: { + name: entrypoint => `runtime-${entrypoint.name}`, + }, + }, + resolve: { + // This allows you to set a fallback for where webpack should look for modules. + // We placed these paths second because we want `node_modules` to "win" + // if there are any conflicts. This matches Node resolution mechanism. + // https://github.com/facebook/create-react-app/issues/253 + modules: ['node_modules', paths.appNodeModules].concat( + modules.additionalModulePaths || [] + ), + // These are the reasonable defaults supported by the Node ecosystem. + // We also include JSX as a common component filename extension to support + // some tools, although we do not recommend using it, see: + // https://github.com/facebook/create-react-app/issues/290 + // `web` extension prefixes have been added for better support + // for React Native Web. + extensions: paths.moduleFileExtensions + .map(ext => `.${ext}`) + .filter(ext => useTypeScript || !ext.includes('ts')), + alias: { + // Support React Native Web + // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ + 'react-native': 'react-native-web', + // Allows for better profiling with ReactDevTools + ...(isEnvProductionProfile && { + 'react-dom$': 'react-dom/profiling', + 'scheduler/tracing': 'scheduler/tracing-profiling', + }), + ...(modules.webpackAliases || {}), + }, + plugins: [ + // Adds support for installing with Plug'n'Play, leading to faster installs and adding + // guards against forgotten dependencies and such. + PnpWebpackPlugin, + // Prevents users from importing files from outside of src/ (or node_modules/). + // This often causes confusion because we only process files within src/ with babel. + // To fix this, we prevent you from importing files out of src/ -- if you'd like to, + // please link the files into your node_modules/ and let module-resolution kick in. + // Make sure your source files are compiled, as they will not be processed in any way. + new ModuleScopePlugin(paths.appSrc, [ + paths.appPackageJson, + paths.packages, + reactRefreshOverlayEntry, + ]), + ], + }, + resolveLoader: { + plugins: [ + // Also related to Plug'n'Play, but this time it tells webpack to load its loaders + // from the current package. + PnpWebpackPlugin.moduleLoader(module), + ], + }, + module: { + strictExportPresence: true, + rules: [ + // Disable require.ensure as it's not a standard language feature. + { parser: { requireEnsure: false } }, + { + // "oneOf" will traverse all following loaders until one will + // match the requirements. When no loader matches it will fall + // back to the "file" loader at the end of the loader list. + oneOf: [ + // TODO: Merge this config once `image/avif` is in the mime-db + // https://github.com/jshttp/mime-db + { + test: [/\.avif$/], + loader: require.resolve('url-loader'), + options: { + limit: imageInlineSizeLimit, + mimetype: 'image/avif', + name: 'static/media/[name].[hash:8].[ext]', + }, + }, + // "url" loader works like "file" loader except that it embeds assets + // smaller than specified limit in bytes as data URLs to avoid requests. + // A missing `test` is equivalent to a match. + { + test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], + loader: require.resolve('url-loader'), + options: { + limit: imageInlineSizeLimit, + name: 'static/media/[name].[hash:8].[ext]', + }, + }, + // Process application JS with Babel. + // The preset includes JSX, Flow, TypeScript, and some ESnext features. + { + test: /\.(js|mjs|jsx|ts|tsx)$/, + include: [paths.appSrc, paths.packages], + loader: require.resolve('babel-loader'), + options: { + customize: require.resolve( + 'babel-preset-react-app/webpack-overrides' + ), + + plugins: [ + [ + require.resolve('babel-plugin-named-asset-import'), + { + loaderMap: { + svg: { + ReactComponent: + '@svgr/webpack?-svgo,+titleProp,+ref![path]', + }, + }, + }, + ], + isEnvDevelopment && + shouldUseReactRefresh && + require.resolve('react-refresh/babel'), + ].filter(Boolean), + // This is a feature of `babel-loader` for webpack (not Babel itself). + // It enables caching results in ./node_modules/.cache/babel-loader/ + // directory for faster rebuilds. + cacheDirectory: true, + // See #6846 for context on why cacheCompression is disabled + cacheCompression: false, + compact: isEnvProduction, + }, + }, + // Process any JS outside of the app with Babel. + // Unlike the application JS, we only compile the standard ES features. + { + test: /\.(js|mjs)$/, + exclude: /@babel(?:\/|\\{1,2})runtime/, + loader: require.resolve('babel-loader'), + options: { + babelrc: false, + configFile: false, + compact: false, + presets: [ + [ + require.resolve('babel-preset-react-app/dependencies'), + { helpers: true }, + ], + ], + cacheDirectory: true, + // See #6846 for context on why cacheCompression is disabled + cacheCompression: false, + + // Babel sourcemaps are needed for debugging into node_modules + // code. Without the options below, debuggers like VSCode + // show incorrect code and set breakpoints on the wrong lines. + sourceMaps: shouldUseSourceMap, + inputSourceMap: shouldUseSourceMap, + }, + }, + // "postcss" loader applies autoprefixer to our CSS. + // "css" loader resolves paths in CSS and adds assets as dependencies. + // "style" loader turns CSS into JS modules that inject