[next] Add support for next/constants (#29633)

* [next] Add support for `next/constants`

* minor whitespace fix
This commit is contained in:
Resi Respati 2018-10-12 00:47:24 +07:00 committed by Andy
parent aa83866295
commit dab682e6f8
3 changed files with 55 additions and 0 deletions

23
types/next/constants.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
export const PHASE_EXPORT: string;
export const PHASE_PRODUCTION_BUILD: string;
export const PHASE_PRODUCTION_SERVER: string;
export const PHASE_DEVELOPMENT_SERVER: string;
export const PAGES_MANIFEST: string;
export const BUILD_MANIFEST: string;
export const REACT_LOADABLE_MANIFEST: string;
export const SERVER_DIRECTORY: string;
export const CONFIG_FILE: string;
export const BUILD_ID_FILE: string;
export const BLOCKED_PAGES: string[];
export const CLIENT_STATIC_FILES_PATH: string;
export const CLIENT_STATIC_FILES_RUNTIME: string;
export const CLIENT_STATIC_FILES_RUNTIME_PATH: string;
/** static/runtime/main.js */
export const CLIENT_STATIC_FILES_RUNTIME_MAIN: string;
/** static/runtime/webpack.js */
export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK: string;
/** matches static/<buildid>/pages/<page>.js */
export const IS_BUNDLED_PAGE_REGEX: RegExp;
/** matches static/<buildid>/pages/:page*.js */
export const ROUTE_NAME_REGEX: RegExp;

View File

@ -0,0 +1,30 @@
import {
PHASE_DEVELOPMENT_SERVER,
IS_BUNDLED_PAGE_REGEX
} from "next/constants";
const isIndexPage = IS_BUNDLED_PAGE_REGEX.test(
"static/CjW0mFnyG80HdP4eSUiy7/pages/index.js"
);
// Example taken from: https://github.com/cyrilwanner/next-compose-plugins/blob/a25b313899638912cc9defc0be072f4fe4a1e855/README.md
const config = (nextConfig: any = {}) => {
return {
...nextConfig,
// define in which phases this plugin should get applied.
// you can also use multiple phases or negate them.
// however, users can still overwrite them in their configuration if they really want to.
phases: [PHASE_DEVELOPMENT_SERVER],
webpack(config: any, options: any) {
// do something here which only gets applied during development server phase
if (typeof nextConfig.webpack === "function") {
return nextConfig.webpack(config, options);
}
return config;
}
};
};

View File

@ -20,6 +20,7 @@
},
"files": [
"index.d.ts",
"constants.d.ts",
"app.d.ts",
"document.d.ts",
"dynamic.d.ts",
@ -29,6 +30,7 @@
"router.d.ts",
"config.d.ts",
"test/next-tests.ts",
"test/next-constants-tests.ts",
"test/next-app-tests.tsx",
"test/next-error-tests.tsx",
"test/next-head-tests.tsx",