0.106.2 • Published 5 days ago

@blaze-cms/nextjs-tools v0.106.2

Weekly downloads
1,605
License
GPL-3.0
Repository
-
Last release
5 days ago

Blaze next.js tools

Provides tools to add blaze to your nextjs project. blaze-nextjs-tools/build has been deprecated and will be removed in the future. Please use/update blaze-nextjs-build-tools for generating next config. Blaze packages are listed in alias.json. Please update this file for shared new blaze dependencies. add third-party alias via project's next.config.js as follows:

const { getNextPlugins, getNextJsConfig } = require('@blaze-cms/nextjs-build-tools');
const withPlugins = require('next-compose-plugins');

const webpackCustomConfig = { plugins: [getSentryPlugin()] };
const config = getNextJsConfig({
  webpackCustomConfig,
  nextJsCustomConfig: {
    srcAliases: {
      '@sentry/browser': '@sentry/browser/esm'
    }
  }
});
const plugins = getNextPlugins();

module.exports = withPlugins(plugins, config);

App ctx

On each route change the app ctx gets set with: router, req, res;

Open Graph

The packages adds og metadata to the head of pages automatically. It uses the following hierarchy to get the domain

Static routes

This package adds routes for some frontend files that will return responses not rendered by react. Currently these requests still initially route through the Resolver. They may be split out in the future.

Currently the static routes and handlers are expandable. The handlers are set in the static route handler config. Any new routes will also be added to the routes config.

The routes handled are described below

/sitemap.xml

This static route outputs a sitemap xml files that it fetches from the api. It does this be querying the api for the latest sitemap index then downloads it and sends the response.

See the sitemap handler to see the api query.

This path can be overriden by setting the BLAZE_ROUTE_PATTERN_SITEMAP env.

/sitemap/filename.xml

This static route outputs a sitemap file xml that it fetches from the api. It does this be querying the api for the latest sitemap by filename then downloads it and sends the response.

See the sitemap file handler to see the api query.

/robots.txt

This static route outputs a robots.txt xml files that it fetches from the api. It does this be querying the api for the latest created file with filename robots.txt from the store specified by process.env.BLAZE_STATIC_ROUTE_STORE_KEY if set or the default store. Then downloads it and sends the response.

So to server a robots.txt file simply upload one to the api with the name robots.txt and it will be served through this route.

See the robots.txt handler to see the api query.

Route regex

The route regex defines what paths will be checked with the api. Any url paths that don't match the regex will return a 404 error.

The default regex can be seen in constants

If you want to make it stricter or more open you can override the default with the environmental variable BLAZE_ROUTE_REGEX.

Note If you make it more open this could increase load on the frontend/api services as more paths will be checked with the api so if bot is targetting the server the load on both services will be higher.

Example

This example will also allow the path to contain . characters

^\/[a-z0-9€_\/]+(?:[-\/\.]{1,2}[a-z0-9\/€_\/]+)*$|^\/$

Environment variables

NameDescriptionDefault
BLAZE_FRONTEND_HOSTFrontend host (used to identify host)String
BLAZE_ROUTE_REGEXOverride default route regex/^\/a-z0-9€_\/+(?:-\/.{1,2}a-z0-9\/€_\/+)*$^\/$/
BLAZE_STATIC_ROUTE_STORE_KEYOverride store for static file routesdefault
BLAZE_ROUTE_PATTERN_SITEMAPOverride sitemap route/sitemap.xml
BLAZE_CONTENT_SITEMAP_URL_PREFIXPrefix for sitemap URL, used in frontend static route e.g. /sitemap/sitemap-0.xml. This needs to match the value set in the API app.String
BLAZE_ROOT_SELECTOR_CLASSES_LIMITThe number of root-selector classes to display. 0 or unset will show noeString
BLAZE_BUILD_ENV_PREFIX_REGEX'|' separated list of allowed environment variable prefixes. Any environment variable that matches this prefix pattern will be dynamically added to the next environment config and will be available in code for use. If the environment variable has a "BUILD" prefix, then this prefix will be removed from the next environment variable name before assigning it. i.e. BUILD_THIRD_PARTY_ENV will become THIRD_PARTY_ENV in the build. Prefixes BLAZE|GOOGLE|JWPLAYER|DFP are added for backward compatibility and will be deprecated. We recommend to use new and change existing environment variables with "BUILD" prefix.BLAZE|GOOGLE|JWPLAYER|DFP|BUILD
BLAZE_CONTENT_SITEMAP_URL_PREFIXPrefix for sitemap URL, used in frontend static route e.g. /sitemap/sitemap-0.xml. This needs to match value set in API app.String

Tailwind

Tailwind CSS is a utility-first CSS framework packed with classes like flex , pt-4 , text-center and rotate-90 that can be composed to build any design, directly in your markup.

Setup

  1. Update next package to version 10 in frontend application

  2. Install tailwindcss, PostCSS and Autoprefixer packages in frontend application

cd packages/frontend/
yarn install tailwindcss@latest postcss@latest autoprefixer@latest --save
  1. Add tailwind.config.js file in packages/frontend with following content
module.exports = {
  purge: ['./src/pages/**/*.js', './src/components/**/*.js'],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {}
  },
  variants: {
    extend: {}
  },
  plugins: []
};
  1. Add postcss.config.js file in packages/frontend with following content
module.exports = {
  plugins: ['tailwindcss', 'autoprefixer']
};

When including Tailwind in your CSS in a Next.js project, there are two approaches you can take: directly in JS or in CSS.

Import Tailwind directly in JS

If you aren't planning to write any custom CSS in your project, the fastest way to include Tailwind is to import it directly in pages/_app.js:

  // pages/_app.js
 import '../styles/globals.css'
 import "tailwindcss/tailwind.css";

  function MyApp({ Component, pageProps }) {
    return <Component {...pageProps} />
  }

  export default MyApp

If you aren't planning to use them, you can safely delete any CSS files Next.js creates for you by default like globals.css and Home.module.css. Make sure you delete any references to them within your components as well.

Include Tailwind in CSS

Open the ./styles/globals.css file that Next.js generates for you by default (if file is missing then create it) and use the @tailwind directive to include Tailwind's base, components, and utilities styles, replacing the original file contents:

/* ./styles/globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Tailwind will swap these directives out at build-time with all of the styles it generates based on your configured design system.

Read our documentation on adding base styles, extracting components, and adding new utilities for best practices on extending Tailwind with your own custom CSS.

Finally, ensure your CSS file is being imported in your pages/_app.js component:

// pages/_app.js
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

If you've chosen to use a different file than the default globals.css file, you'll want to update the import accordingly.

Frontend checks

When checking new code or build configs make sure to check the following things.

Root selector classes

To make styling of sections of a site simpler, it is possible to enable setting root selector classes at the top of the Resolver page structure that are generated based on the url hierarchy.

For example the following url, /parent/child/article-123 might be broken into the following classes

root-selector--parent
root-selector--parent--child
root-selector--parent--child--article-123

To enable this the BLAZE_ROOT_SELECTOR_CLASSES_LIMIT env variable must be set to the number of classes you want to display e.g. if you want just the parent section set this to 1 and the only class will be root-selector--parent.

Note If this variable is set then the home page will have the classes root-selector.

Because of the url restrictions in core blaze the classes shouldn't need escaping/replacing as all characters should be supported.

0.107.0-alpha.0

5 days ago

0.106.1

6 days ago

0.106.2

5 days ago

0.106.0

7 days ago

0.106.0-alpha.0

10 days ago

0.105.1

11 days ago

0.105.0-alpha.7

12 days ago

0.105.0-alpha.6

13 days ago

0.105.0-alpha.4

13 days ago

0.105.0

12 days ago

0.104.1

18 days ago

0.104.2

18 days ago

0.105.0-alpha.1

18 days ago

0.105.0-alpha.0

18 days ago

0.104.0

20 days ago

0.104.0-alpha.5

20 days ago

0.104.0-alpha.3

24 days ago

0.104.0-alpha.2

24 days ago

0.104.0-alpha.1

25 days ago

0.104.0-alpha.0

25 days ago

0.104.0-alpha.4

24 days ago

0.103.0

27 days ago

0.103.0-alpha.6

1 month ago

0.103.0-alpha.3

1 month ago

0.102.2

1 month ago

0.103.0-alpha.2

1 month ago

0.103.0-alpha.1

2 months ago

0.102.1

2 months ago

0.102.1-alpha.0

2 months ago

0.102.0

2 months ago

0.102.0-alpha.4

2 months ago

0.101.2

2 months ago

0.102.0-alpha.2

2 months ago

0.102.0-alpha.0

2 months ago

0.101.0

2 months ago

0.101.0-alpha.3

2 months ago

0.101.0-alpha.1

2 months ago

0.101.0-alpha.0

3 months ago

0.100.0

3 months ago

0.100.0-alpha.4

3 months ago

0.99.0

3 months ago

0.100.0-alpha.2

3 months ago

0.100.0-alpha.0

3 months ago

0.100.0-alpha.1

3 months ago

0.99.0-alpha.1

3 months ago

0.99.0-alpha.0

3 months ago

0.98.0

3 months ago

0.98.0-alpha.1

3 months ago

0.98.0-alpha.0

3 months ago

0.97.3

3 months ago

0.97.3-alpha.1

3 months ago

0.97.3-alpha.0

3 months ago

0.97.0-alpha.16

4 months ago

0.97.0-alpha.13

4 months ago

0.97.0-alpha.12

4 months ago

0.97.0-alpha.15

4 months ago

0.97.0-alpha.14

4 months ago

0.97.0-alpha.11

4 months ago

0.97.0-alpha.10

4 months ago

0.97.2-alpha.2

4 months ago

0.97.2

4 months ago

0.97.2-alpha.0

4 months ago

0.97.0

4 months ago

0.97.0-alpha.8

4 months ago

0.97.0-alpha.7

4 months ago

0.97.0-alpha.6

4 months ago

0.97.0-alpha.5

4 months ago

0.97.0-alpha.4

4 months ago

0.97.0-alpha.3

4 months ago

0.97.0-alpha.2

4 months ago

0.97.0-alpha.1

4 months ago

0.97.0-alpha.0

4 months ago

0.96.0

4 months ago

0.94.0

5 months ago

0.95.1-alpha.0

5 months ago

0.95.1-alpha.1

5 months ago

0.95.1-alpha.2

5 months ago

0.94.1-alpha.1

5 months ago

0.94.1-alpha.0

5 months ago

0.95.0

5 months ago

0.95.0-alpha.0

5 months ago

0.96.0-alpha.4

4 months ago

0.96.0-alpha.0

5 months ago

0.96.0-alpha.1

4 months ago

0.96.0-alpha.2

4 months ago

0.96.0-alpha.3

4 months ago

0.94.0-alpha.5

5 months ago

0.94.0-alpha.3

6 months ago

0.94.0-alpha.0

6 months ago

0.93.0

6 months ago

0.93.0-alpha.0

6 months ago

0.92.2

6 months ago

0.92.2-alpha.0

7 months ago

0.92.1

7 months ago

0.92.1-alpha.0

7 months ago

0.92.0

7 months ago

0.92.0-alpha.2

7 months ago

0.92.0-alpha.1

7 months ago

0.92.0-alpha.0

7 months ago

0.91.0

7 months ago

0.91.0-alpha.1

7 months ago

0.90.0

7 months ago

0.90.0-alpha.0

7 months ago

0.89.0

7 months ago

0.89.0-alpha.0

7 months ago

0.88.0

8 months ago

0.87.0

8 months ago

0.87.0-alpha.1

8 months ago

0.87.0-alpha.0

8 months ago

0.86.0-alpha.0

8 months ago

0.85.0-alpha.0

8 months ago

0.84.0-alpha.0

8 months ago

0.83.2-alpha.0

8 months ago

0.83.1-alpha.0

9 months ago

0.83.0-alpha.0

9 months ago

0.82.0-alpha.0

9 months ago

0.81.1-alpha.0

9 months ago

0.80.0-alpha.0

9 months ago

0.79.0-alpha.0

9 months ago

0.78.1-alpha.0

9 months ago

0.78.2-alpha.0

9 months ago

0.78.0-alpha.0

9 months ago

0.76.0-alpha.0

10 months ago

0.74.1-alpha.0

10 months ago

0.74.0-alpha.0

10 months ago

0.72.0-alpha.0

10 months ago

0.73.0-alpha.0

10 months ago

0.71.2-alpha.0

10 months ago

0.71.1-alpha.0

10 months ago

0.70.2-alpha.0

10 months ago

0.70.1-alpha.0

10 months ago

0.70.0-alpha.0

10 months ago

0.69.0-alpha.0

10 months ago

0.68.5-alpha.0

10 months ago

0.68.4-alpha.0

10 months ago

0.68.3-alpha.0

11 months ago

0.68.1-alpha.0

11 months ago

0.68.2-alpha.0

11 months ago

0.67.0-alpha.0

11 months ago

0.68.0-alpha.0

11 months ago

0.66.0-alpha.0

11 months ago

0.64.0-alpha.0

11 months ago

0.63.0-alpha.0

11 months ago

0.62.0-alpha.0

11 months ago

0.59.5-alpha.0

11 months ago

0.61.0-alpha.0

11 months ago

0.60.0-alpha.0

11 months ago

0.59.4-alpha.0

11 months ago

0.59.3-alpha.0

11 months ago

0.59.2-alpha.0

11 months ago

0.58.3-alpha.0

11 months ago

0.59.1-alpha.0

11 months ago

0.58.2-alpha.0

11 months ago

0.58.1-alpha.0

11 months ago

0.57.0-alpha.0

11 months ago

0.56.0-alpha.0

11 months ago

0.55.0-alpha.0

12 months ago

0.54.1-alpha.0

12 months ago

0.54.0-alpha.0

12 months ago

0.53.3-alpha.0

12 months ago

0.53.2-alpha.0

12 months ago

0.53.1-alpha.0

12 months ago

0.53.0-alpha.0

12 months ago

0.52.0-alpha.0

12 months ago

0.51.0-alpha.0

12 months ago

0.50.0-alpha.0

12 months ago

0.49.3-alpha.0

12 months ago

0.49.2-alpha.0

12 months ago

0.49.1-alpha.0

12 months ago

0.49.0-alpha.0

12 months ago

0.48.1-alpha.0

12 months ago

0.48.0-alpha.0

1 year ago

0.47.0-alpha.0

1 year ago

0.46.1-alpha.0

1 year ago

0.46.0-alpha.0

1 year ago

0.45.2-alpha.0

1 year ago

0.45.1-alpha.0

1 year ago

0.45.0-alpha.0

1 year ago

0.44.2-alpha.0

1 year ago

0.44.1-alpha.0

1 year ago

0.43.1-alpha.0

1 year ago

0.43.0-alpha.0

1 year ago

0.42.5-alpha.0

1 year ago

0.42.1-alpha.0

1 year ago

0.42.0-alpha.0

1 year ago

0.41.2-alpha.0

1 year ago

0.41.1-alpha.0

1 year ago

0.41.0-alpha.0

1 year ago

0.40.1-alpha.0

1 year ago

0.40.2-alpha.0

1 year ago

0.40.0-alpha.0

1 year ago

0.39.17-alpha.0

1 year ago

0.39.18-alpha.0

1 year ago

0.39.16-alpha.0

1 year ago

0.39.14-alpha.0

1 year ago

0.39.12-alpha.0

1 year ago

0.39.13-alpha.0

1 year ago

0.39.11-alpha.0

1 year ago

0.39.10-alpha.0

1 year ago

0.39.9-alpha.0

1 year ago

0.39.8-alpha.0

1 year ago

0.39.7-alpha.0

1 year ago

0.39.6-alpha.0

1 year ago

0.39.5-alpha.0

1 year ago

0.39.4-alpha.0

1 year ago

0.39.3-alpha.0

1 year ago

0.39.2-alpha.0

1 year ago

0.38.7-alpha.0

1 year ago

0.38.5-alpha.0

1 year ago

0.38.6-alpha.0

1 year ago

0.38.4-alpha.0

1 year ago

0.38.3-alpha.0

1 year ago

0.38.1-alpha.0

1 year ago

0.38.0-alpha.0

1 year ago

0.37.53-alpha.0

1 year ago

0.37.54-alpha.0

1 year ago

0.37.51-alpha.0

1 year ago

0.37.52-alpha.0

1 year ago

0.37.50-alpha.0

1 year ago

0.37.48-alpha.0

1 year ago

0.37.46-alpha.0

1 year ago

0.37.45-alpha.0

1 year ago

0.37.44-alpha.0

1 year ago

0.37.42-alpha.0

1 year ago

0.37.41-alpha.0

1 year ago

0.37.40-alpha.0

1 year ago

0.37.39-alpha.0

1 year ago

0.37.38-alpha.0

1 year ago

0.37.37-alpha.0

1 year ago

0.37.36-alpha.0

1 year ago

0.37.35-alpha.0

1 year ago

0.37.33-alpha.0

1 year ago

0.37.32-alpha.0

1 year ago

0.37.31-alpha.0

1 year ago

0.37.30-alpha.0

1 year ago

0.37.29-alpha.0

1 year ago

0.37.28-alpha.0

1 year ago

0.37.27-alpha.0

1 year ago

0.37.26-alpha.0

1 year ago

0.37.25-alpha.0

1 year ago

0.37.24-alpha.0

1 year ago

0.37.23-alpha.0

1 year ago

0.37.21-alpha.0

1 year ago

0.37.22-alpha.0

1 year ago

0.37.19-alpha.0

1 year ago

0.37.20-alpha.0

1 year ago

0.37.18-alpha.0

1 year ago

0.37.17-alpha.0

1 year ago

0.37.16-alpha.0

1 year ago

0.37.15-alpha.0

1 year ago

0.37.14-alpha.0

1 year ago

0.37.13-alpha.0

1 year ago

0.37.12-alpha.0

1 year ago

0.37.11-alpha.0

1 year ago

0.37.10-alpha.0

1 year ago

0.37.8-alpha.0

1 year ago

0.37.9-alpha.0

1 year ago

0.37.7-alpha.0

1 year ago

0.37.6-alpha.0

1 year ago

0.37.5-alpha.0

1 year ago

0.37.3-alpha.0

1 year ago

0.37.0-alpha.0

1 year ago

0.37.2-alpha.0

1 year ago

0.36.1-alpha.0

1 year ago

0.36.0-alpha.0

1 year ago

0.35.5-alpha.0

2 years ago

0.35.4-alpha.0

2 years ago

0.35.2-alpha.0

2 years ago

0.35.3-alpha.0

2 years ago

0.34.0-alpha.0

2 years ago

0.33.0-alpha.0

2 years ago

0.32.0-alpha.0

2 years ago

0.31.30-alpha.0

2 years ago

0.31.29-alpha.0

2 years ago

0.31.27-alpha.0

2 years ago

0.31.28-alpha.0

2 years ago

0.31.26-alpha.0

2 years ago

0.31.25-alpha.0

2 years ago

0.31.24-alpha.0

2 years ago

0.31.23-alpha.0

2 years ago

0.31.20-alpha.0

2 years ago

0.31.19-alpha.0

2 years ago

0.31.18-alpha.0

2 years ago

0.31.17-alpha.0

2 years ago

0.31.16-alpha.0

2 years ago

0.31.14-alpha.0

2 years ago

0.31.13-alpha.0

2 years ago

0.31.11-alpha.0

2 years ago

0.31.10-alpha.0

2 years ago

0.31.9-alpha.0

2 years ago

0.31.8-alpha.0

2 years ago

0.31.7-alpha.0

2 years ago

0.31.6-alpha.0

2 years ago

0.31.3-alpha.0

2 years ago

0.31.4-alpha.0

2 years ago

0.31.5-alpha.0

2 years ago

0.31.1-alpha.0

2 years ago

0.30.9-alpha.0

2 years ago

0.31.0-alpha.0

2 years ago

0.30.8-alpha.0

2 years ago

0.30.7-alpha.0

2 years ago

0.30.6-alpha.0

2 years ago

0.30.5-alpha.0

2 years ago

0.30.4-alpha.0

2 years ago

0.30.2-alpha.0

2 years ago

0.30.1-alpha.0

2 years ago

0.30.0-alpha.0

2 years ago

0.29.3-alpha.0

2 years ago

0.29.1-alpha.0

2 years ago

0.29.0-alpha.0

2 years ago

0.28.5-alpha.0

2 years ago

0.28.3-alpha.0

2 years ago

0.28.1-alpha.0

2 years ago

0.28.2-alpha.0

2 years ago

0.28.0-alpha.0

2 years ago

0.27.3-alpha.0

2 years ago

0.27.4-alpha.0

2 years ago

0.27.0-alpha.0

2 years ago

0.26.2-alpha.0

2 years ago

0.26.1-alpha.0

2 years ago

0.26.0-alpha.0

2 years ago

0.25.7-alpha.0

2 years ago

0.25.6-alpha.0

2 years ago

0.25.4-alpha.0

2 years ago

0.25.5-alpha.0

2 years ago

0.25.3-alpha.0

2 years ago

0.25.1-alpha.0

2 years ago

0.25.0-alpha.0

2 years ago

0.24.2-alpha.0

2 years ago

0.24.0-alpha.0

2 years ago

0.23.0-alpha.0

2 years ago

0.22.0-alpha.0

2 years ago

0.21.0-alpha.0

2 years ago

0.20.6-alpha.0

2 years ago

0.20.5-alpha.0

2 years ago

0.20.4-alpha.0

2 years ago

0.20.3-alpha.0

2 years ago

0.20.2-alpha.0

2 years ago

0.20.0-alpha.0

2 years ago

0.19.2-alpha.0

2 years ago

0.19.1-alpha.0

2 years ago

0.19.0-alpha.0

2 years ago

0.18.0-alpha.0

2 years ago

0.17.0-alpha.0

2 years ago

0.16.1-alpha.0

2 years ago

0.16.0-alpha.0

2 years ago

0.15.1-alpha.0

2 years ago

0.14.7-alpha.0

2 years ago

0.14.6-alpha.0

2 years ago

0.14.5-alpha.0

2 years ago

0.14.3-alpha.0

2 years ago

0.14.2-alpha.0

2 years ago

0.14.0-alpha.0

2 years ago

0.13.4-alpha.0

2 years ago

0.13.0-alpha.0

2 years ago

0.12.8-alpha.0

2 years ago

0.12.7-alpha.0

2 years ago

0.12.6-alpha.0

2 years ago

0.12.5-alpha.0

2 years ago

0.12.4-alpha.0

2 years ago

0.12.3-alpha.0

2 years ago

0.12.2-alpha.0

2 years ago

0.12.0-alpha.0

2 years ago

0.11.3-alpha.0

2 years ago

0.11.2-alpha.0

2 years ago

0.11.1-alpha.0

2 years ago

0.11.0-alpha.0

2 years ago

0.10.6-alpha.0

2 years ago

0.10.5-alpha.0

2 years ago

0.10.4-alpha.0

2 years ago

0.10.3-alpha.0

2 years ago

0.10.2-alpha.0

2 years ago

0.10.1-alpha.0

2 years ago

0.10.0-alpha.0

2 years ago

0.9.2-alpha.0

2 years ago

0.9.1-alpha.0

2 years ago

0.9.0-alpha.0

2 years ago

0.8.0-alpha.0

2 years ago

0.7.1-alpha.0

2 years ago

0.7.0-alpha.0

2 years ago

0.6.2-alpha.0

2 years ago

0.6.0-alpha.0

2 years ago

0.5.4-alpha.0

2 years ago

0.5.3-alpha.0

2 years ago

0.5.2-alpha.0

2 years ago

0.5.1-alpha.0

2 years ago

0.5.0-alpha.0

2 years ago

0.4.0-alpha.0

2 years ago

0.3.7-alpha.0

2 years ago

0.3.6-alpha.0

2 years ago

0.3.5-alpha.0

2 years ago

0.3.4-alpha.0

2 years ago

0.3.3-alpha.0

2 years ago

0.3.2-alpha.0

2 years ago

0.3.1-alpha.0

2 years ago

0.3.0-alpha.0

2 years ago

0.2.1-alpha.0

2 years ago

0.2.0-alpha.0

2 years ago