remix.config.js

This file has a few build and development configuration options, but does not actually run on your server.

  1. /** @type {import('@remix-run/dev').AppConfig} */
  2. module.exports = {
  3. appDirectory: "app",
  4. assetsBuildDirectory: "public/build",
  5. ignoredRouteFiles: ["**/.*"],
  6. publicPath: "/build/",
  7. routes(defineRoutes) {
  8. return defineRoutes((route) => {
  9. route("/somewhere/cool/*", "catchall.tsx");
  10. });
  11. },
  12. serverBuildPath: "build/index.js",
  13. };

appDirectory

The path to the app directory, relative to remix.config.js. Defaults to "app".

  1. // default
  2. exports.appDirectory = "./app";
  3. // custom
  4. exports.appDirectory = "./elsewhere";

assetsBuildDirectory

The path to the browser build, relative to remix.config.js. Defaults to “public/build”. Should be deployed to static hosting.

cacheDirectory

The path to a directory Remix can use for caching things in development, relative to remix.config.js. Defaults to ".cache".

devServerBroadcastDelay (deprecated)

The delay, in milliseconds, before the dev server broadcasts a reload event. There is no delay by default.

For v2_dev, the race conditions that necesitated this option have been eliminated.

devServerPort (deprecated)

The port number to use for the dev websocket server. Defaults to 8002.

For v2_dev, use --port / v2_dev.port option.

ignoredRouteFiles

This is an array of globs (via minimatch) that Remix will match to files while reading your app/routes directory. If a file matches, it will be ignored rather than treated like a route module. This is useful for ignoring dotfiles (like .DS_Store files) or CSS/test files you wish to colocate.

publicPath

The URL prefix of the browser build with a trailing slash. Defaults to "/build/". This is the path the browser will use to find assets.

postcss

Whether to process CSS using PostCSS if postcss.config.js is present. Defaults to false.

routes

A function for defining custom routes, in addition to those already defined using the filesystem convention in app/routes. Both sets of routes will be merged.

  1. exports.routes = async (defineRoutes) => {
  2. // If you need to do async work, do it before calling `defineRoutes`, we use
  3. // the call stack of `route` inside to set nesting.
  4. return defineRoutes((route) => {
  5. // A common use for this is catchall routes.
  6. // - The first argument is the React Router path to match against
  7. // - The second is the relative filename of the route handler
  8. route("/some/path/*", "catchall.tsx");
  9. // if you want to nest routes, use the optional callback argument
  10. route("some/:path", "some/route/file.js", () => {
  11. // - path is relative to parent path
  12. // - filenames are still relative to the app directory
  13. route("relative/path", "some/other/file");
  14. });
  15. });
  16. };

server

A server entrypoint, relative to the root directory that becomes your server’s main module. If specified, Remix will compile this file along with your application into a single file to be deployed to your server. This file can use either a .js or .ts file extension.

serverBuildDirectory

This option is deprecated and will likely be removed in a future stable release. Use serverBuildPath instead.

The path to the server build, relative to remix.config.js. Defaults to “build”. This needs to be deployed to your server.

serverBuildPath

The path to the server build file, relative to remix.config.js. This file should end in a .js extension and should be deployed to your server. Defaults to "build/index.js".

serverBuildTarget

This option is deprecated and will be removed in the next major version release. Use a combination of publicPath, serverBuildPath, serverConditions, serverDependenciesToBundle serverMainFields, serverMinify, serverModuleFormat and/or serverPlatform instead.

The target of the server build. Defaults to "node-cjs".

The serverBuildTarget can be one of the following:

serverConditions

The order of conditions to use when resolving server dependencies’ exports field in package.json.

serverDependenciesToBundle

A list of regex patterns that determines if a module is transpiled and included in the server bundle. This can be useful when consuming ESM only packages in a CJS build, or when consuming packages with CSS side effect imports.

For example, the unified ecosystem is all ESM-only. Let’s also say we’re using a @sindresorhus/slugify which is ESM-only as well. Here’s how you would be able to consume those packages in a CJS app without having to use dynamic imports:

  1. /** @type {import('@remix-run/dev').AppConfig} */
  2. module.exports = {
  3. appDirectory: "app",
  4. assetsBuildDirectory: "public/build",
  5. publicPath: "/build/",
  6. serverBuildDirectory: "build",
  7. ignoredRouteFiles: ["**/.*"],
  8. serverDependenciesToBundle: [
  9. /^rehype.*/,
  10. /^remark.*/,
  11. /^unified.*/,
  12. "@sindresorhus/slugify",
  13. ],
  14. };

If you want to bundle all server dependencies, you can set serverDependenciesToBundle to "all".

serverMainFields

The order of main fields to use when resolving server dependencies. Defaults to ["main", "module"] when serverModuleFormat is set to "cjs". Defaults to ["module", "main"] when serverModuleFormat is set to "esm".

serverMinify

Whether to minify the server build in production or not. Defaults to false.

serverModuleFormat

The output format of the server build, which can either be "cjs" or "esm". Defaults to "cjs".

serverNodeBuiltinsPolyfill

The Node.js polyfills to include in the server build when targeting non-Node.js server platforms. Polyfills are provided by JSPM and configured via esbuild-plugins-node-modules-polyfill.

  1. exports.serverNodeBuiltinsPolyfill = {
  2. modules: {
  3. path: true, // Provide a JSPM polyfill
  4. fs: "empty", // Provide an empty polyfill
  5. },
  6. };

If left unset, this config defaults to the following set of polyfills for non-Node.js server platforms:

  1. exports.serverNodeBuiltinsPolyfill = {
  2. modules: {
  3. _stream_duplex: true,
  4. _stream_passthrough: true,
  5. _stream_readable: true,
  6. _stream_transform: true,
  7. _stream_writable: true,
  8. assert: true,
  9. "assert/strict": true,
  10. buffer: true,
  11. console: true,
  12. constants: true,
  13. crypto: "empty",
  14. diagnostics_channel: true,
  15. domain: true,
  16. events: true,
  17. fs: "empty",
  18. "fs/promises": "empty",
  19. http: true,
  20. https: true,
  21. module: true,
  22. os: true,
  23. path: true,
  24. "path/posix": true,
  25. "path/win32": true,
  26. perf_hooks: true,
  27. process: true,
  28. punycode: true,
  29. querystring: true,
  30. stream: true,
  31. "stream/promises": true,
  32. "stream/web": true,
  33. string_decoder: true,
  34. sys: true,
  35. timers: true,
  36. "timers/promises": true,
  37. tty: true,
  38. url: true,
  39. util: true,
  40. "util/types": true,
  41. vm: true,
  42. wasi: true,
  43. worker_threads: true,
  44. zlib: true,
  45. },
  46. };

This default behavior is changing in Remix v2 and will no longer polyfill any Node built-in modules on non-Node.js platforms by default. If your app requires polyfills, you will need to manually specify them via this setting. It’s recommend to start manually specifying required polyfills for your app in v1 to ease your eventual migration to v2.

serverPlatform

The platform the server build is targeting, which can either be "neutral" or "node". Defaults to "node".

tailwind

Whether to support Tailwind functions and directives in CSS files if tailwindcss is installed. Defaults to false.

watchPaths

An array, string, or async function that defines custom directories, relative to the project root, to watch while running remix dev. These directories are in addition to appDirectory.

  1. exports.watchPaths = async () => {
  2. return ["./some/path/*"];
  3. };
  4. // also valid
  5. exports.watchPaths = ["./some/path/*"];

File Name Conventions

There are a few conventions that Remix uses you should be aware of.

Dilum Sanjaya made an awesome visualization of how routes in the file system map to the URL in your app that might help you understand these conventions.