1. 07 6月, 2020 1 次提交
  2. 05 6月, 2020 1 次提交
    • J
      Fix pages/index.js and pages/index/index.js behavior (#13699) · 1b36f0c0
      Jan Potoms 提交于
      Disambiguate between pages/index.js and pages/index/index.js so that they resolve differently.
      It all started with a bug in pagesmanifest that propagated throughout the codebase. After fixing pagesmanifest I was able to remove a few hacks here and there and more logic is shared now. especially the logic that resolves an entrypoint back into a route path. To sum up what happened:
      
      - `getRouteFromEntrypoint` is the inverse operation of `getPageFile` that's under `pages/_document.tsx`
      - `denormalizePagePath` is the inverse operation of `normalizePagePath`.
      
      Everything is refactored in terms of these operations, that makes their behavior uniform and easier to update/patch in a central place. Before there were subtle differences between those that made `index/index.js` hard to handle.
      
      Some potential follow up on this PR:
      - [`hot-reloader`](https://github.com/vercel/next.js/pull/13699/files#diff-6161346d2c5f4b7abc87059d8768c44bR207) still has one place that does very similar behavior to `getRouteFromEntrypoint`. It can probably be rewritten in terms of `getRouteFromEntrypoint`.
      - There are a few places where `denormalizePagePath(normalizePagePath(...))` is happening. This is a sign that `normalizePagePath` is doing some validation that is independent of its rewriting logic. That should probably be factored out in its own function. after that I should probably investigate whether `normalizePagePath` is even still needed at all.
      - a lot of code is doing `.replace(/\\/g, '')`. If wanted, that could be replaced with `normalizePathSep`.
      - It looks to me like some logic that's spread across the project can be centralized in 4 functions 
        - `getRouteFromEntrypoint` (part of this PR)
        - its inverse `getEntrypointFromRoute` (already exists in `_document.tsx` as `getPageFile`)
        - `getRouteFromPageFile` 
        - its inverse `getPageFileFromRoute` (already exists as `findPageFile ` in `server/lib/find-page-file.ts`)
      
        It could be beneficial to structure the code to keep these fuctionalities close together and name them similarly.
       - revise `index.amp` handling in pagesmanifest. I left it alone in this PR to keep it scoped, but it may be broken wrt nested index files as well. It might even make sense to reshape the pagesmanifest altogether to handle html/json/amp/... better
      1b36f0c0
  3. 01 3月, 2020 1 次提交
  4. 04 9月, 2019 1 次提交
    • T
      Move next-server back into `next` package (#8613) · 2ba352da
      Tim Neutkens 提交于
      * Initial move
      
      * Make emitting work
      
      * Update paths
      
      * Remove leftover files
      
      * Add correct externals configuration
      
      * Import correct path
      
      * Update path to work with ts-server test
      
      * Update lib directory
      
      * Compile next-server/lib
      2ba352da
  5. 29 5月, 2019 1 次提交
    • T
      Move syntax formatting to prettier (#7454) · 3e51ddb8
      Tim Neutkens 提交于
      * Run prettier over packages/**/*.js
      
      * Run prettier over packages/**/*.ts
      
      * Run prettier over examples
      
      * Remove tslint
      
      * Run prettier over examples
      
      * Run prettier over all markdown files
      
      * Run prettier over json files
      3e51ddb8
  6. 18 4月, 2019 1 次提交
  7. 12 4月, 2019 1 次提交
    • J
      Replace `.amp.js` with `withAmp(Comp)` (#7009) · e5111745
      JJ Kasper 提交于
      * Add WithAmp to enable AMP support for
      pages instead of .amp.js
      
      * Update handling for exporting AMP
      
      * Fix ampPath in export for / path and
      revert isAmp logic to handle right
      
      * Update amphtml test suite
      
      * Add handling for noDirtyAmp during
      export and update amp-export test suite
      
      * Update serverless and export-default-map
      test suites
      
      * Update require-page tests
      e5111745
  8. 03 4月, 2019 1 次提交
    • J
      Add optimizing AMP pages (#6835) · 6344c5f0
      JJ Kasper 提交于
      * Added amp-toolbox-optimizer and added
      optimizing AMP pages as dirty and clean
      
      * Fix amp-optimizer breaking serverless build
      
      * Exclude amp-toolbox-optimizer from serverless build
      
      * Added check to make sure hybrid AMP pages
      optimize cleanly during export
      
      * Add check to make sure noDirtyAmp is applied
      6344c5f0
  9. 19 3月, 2019 1 次提交
    • J
      Add support for creating AMP pages (#6706) · 12cbb934
      JJ Kasper 提交于
      * Add support for .amp.js pages and
      resolving /page?amp=1 to page.amp.js
      
      * Update amp tests
      
      * Update example and clean up amp page resolving
      
      * Add nested amp test
      
      * page => normalizedPage
      
      * Add type to page options
      
      * Add handling of amp with all pageExtensions
      and normalize page
      
      * Make sure findPageFile only falls back to
      amp if enabled
      12cbb934
  10. 31 12月, 2018 1 次提交
    • A
      Implement tslint for core files (#5952) · 20fe65ce
      Anderson Leite 提交于
      Fixes #5845 
      
      Implement tslint for core files
      
      **What is this?**
      Implements tslint for both next and next-server, but keeps standardjs/eslint for the .js files that are still there, we're gradually migrating to Typescript.
      
      **How does it work?**
      Before every commit (pre-commit) we execute the following `tslint` command:
      `tslint -c tslint.json 'packages/**/*.ts`
      
      **TSLint Rules**
      In order to avoid as much changes as possible I marked some rules as false. This way we can improve the linter but making sure this step will not break things. (see tslint.json)
      
      **Note**
      After merging this PR, you'll need to update your dependencies since it adds tslint to package.json
      20fe65ce
  11. 28 12月, 2018 1 次提交
    • T
      Serverless Next.js (#5927) · 0f23faf8
      Tim Neutkens 提交于
      **This does not change existing behavior.**
      
      building to serverless is completely opt-in.
      
      - Implements `target: 'serverless'` in `next.config.js`
      - Removes `next build --lambdas` (was only available on next@canary so far)
      
      This implements the concept of build targets. Currently there will be 2 build targets:
      
      - server (This is the target that already existed / the default, no changes here)
      - serverless (New target aimed at compiling pages to serverless handlers)
      
      The serverless target will output a single file per `page` in the `pages` directory:
      
      - `pages/index.js` => `.next/serverless/index.js`
      - `pages/about.js` => `.next/serverless/about.js`
      
      So what is inside `.next/serverless/about.js`? All the code needed to render that specific page. It has the Node.js `http.Server` request handler function signature:
      
      ```ts
      (req: http.IncomingMessage, res: http.ServerResponse) => void
      ```
      
      So how do you use it? Generally you **don't** want to use the below example, but for illustration purposes it's shown how the handler is called using a plain `http.Server`:
      
      ```js
      const http = require('http')
      // Note that `.default` is needed because the exported module is an esmodule
      const handler = require('./.next/serverless/about.js').default
      const server = new http.Server((req, res) => handler(req, res))
      server.listen(3000, () => console.log('Listening on http://localhost:3000'))
      ```
      
      Generally you'll upload this handler function to an external service like [Now v2](https://zeit.co/now-2), the `@now/next` builder will be updated to reflect these changes. This means that it'll be no longer neccesary for `@now/next` to do some of the guesswork in creating smaller handler functions. As Next.js will output the smallest possible serverless handler function automatically.
      
      The function has 0 dependencies so no node_modules are required to run it, and is generally very small. 45Kb zipped is the baseline, but I'm sure we can make it even smaller in the future.
      
      One important thing to note is that the function won't try to load `next.config.js`, so `publicRuntimeConfig` / `serverRuntimeConfig` are not supported. Reasons are outlined here: #5846
      
      So to summarize:
      
      - every page becomes a serverless function
      - the serverless function has 0 dependencies (they're all inlined)
      - "just" uses the `req` and `res` coming from Node.js
      - opt-in using `target: 'serverless'` in `next.config.js`
      - Does not load next.config.js when executing the function
      
      TODO:
      
      - [x] Compile next/dynamic / `import()` into the function file, so that no extra files have to be uploaded.
      - [x] Setting `assetPrefix` at build time for serverless target
      - [x] Support custom /_app
      - [x] Support custom /_document
      - [x] Support custom /_error
      - [x] Add `next.config.js` property for `target`
      
      Need discussion:
      - [ ] Since the serverless target won't support `publicRuntimeConfig` / `serverRuntimeConfig` as they're runtime values. I think we should support build-time env var replacement with webpack.DefinePlugin or similar.
      - [ ] Serving static files with the correct cache-control, as there is no static file serving in the serverless target
      0f23faf8
  12. 19 12月, 2018 1 次提交
    • T
      Move out requires from renderToHTML (#5915) · 32451e97
      Tim Neutkens 提交于
      This brings us one step closer to outputting serverless functions as renderToHTML now renders the passed components, which allows us to bundle the renderToHTML function together with statically imported components in webpack.
      32451e97
  13. 07 12月, 2018 1 次提交