-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move build directory outside of server folder #4565
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b71bc64
Move build directory outside of server folder
timneutkens 9a4bbe7
Fix reference to promisify
timneutkens 64ae78c
Merge branch 'canary' of github.com:zeit/next.js into add/move-build
timneutkens c7cadee
Load from the right location
timneutkens 06d637b
Load webpack config from new build directory
timneutkens 9c9990a
Manage `nextPagesDir` in one place
timneutkens 3173043
Pass through the correct directories
timneutkens 3aabdfa
Remove comment marking a block
timneutkens 76ea4dd
Merge branch 'canary' of github.com:zeit/next.js into add/move-build
timneutkens 91ac223
Pass pages directory to hot-self-accept loader. Breaking change for n…
timneutkens c10588b
Rename selfAccept to hotSelfAccept
timneutkens 37a39af
Document `defaultLoaders`
timneutkens 45af143
Read from loader options
timneutkens 9d6b616
hot-self-accept for internal pages never worked
timneutkens 6c7803f
Use exact type
timneutkens e1b46ec
Rename regex constants
timneutkens 14977c9
Add example of using defaultLoaders.babel
timneutkens f2be418
Merge branch 'canary' of github.com:zeit/next.js into add/move-build
timneutkens f5e0fce
Right value for loader example
timneutkens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./dist/server/build/babel/preset') | ||
module.exports = require('./dist/build/babel/preset') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...er/build/plugins/build-manifest-plugin.js → build/plugins/build-manifest-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
server/build/plugins/pages-plugin.js → build/plugins/pages-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,7 @@ import DynamicChunksPlugin from './plugins/dynamic-chunks-plugin' | |
import UnlinkFilePlugin from './plugins/unlink-file-plugin' | ||
import PagesManifestPlugin from './plugins/pages-manifest-plugin' | ||
import BuildManifestPlugin from './plugins/build-manifest-plugin' | ||
import {SERVER_DIRECTORY} from '../../lib/constants' | ||
|
||
const nextDir = path.join(__dirname, '..', '..', '..') | ||
const nextNodeModulesDir = path.join(nextDir, 'node_modules') | ||
const nextPagesDir = path.join(nextDir, 'pages') | ||
import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR} from '../lib/constants' | ||
|
||
function externalsConfig (dir, isServer) { | ||
const externals = [] | ||
|
@@ -57,6 +53,15 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer | |
babel: { | ||
loader: 'next-babel-loader', | ||
options: {dev, isServer} | ||
}, | ||
hotSelfAccept: { | ||
loader: 'hot-self-accept-loader', | ||
options: { | ||
include: [ | ||
path.join(dir, 'pages') | ||
], | ||
extensions: /\.(js|jsx)$/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick, but how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended to not confuse people reading the code. |
||
} | ||
} | ||
} | ||
|
||
|
@@ -65,13 +70,13 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer | |
.split(process.platform === 'win32' ? ';' : ':') | ||
.filter((p) => !!p) | ||
|
||
const pagesEntries = await getPages(dir, {dev, isServer, pageExtensions: config.pageExtensions.join('|')}) | ||
const pagesEntries = await getPages(dir, {nextPagesDir: DEFAULT_PAGES_DIR, dev, isServer, pageExtensions: config.pageExtensions.join('|')}) | ||
const totalPages = Object.keys(pagesEntries).length | ||
const clientEntries = !isServer ? { | ||
'main.js': [ | ||
dev && !isServer && path.join(__dirname, '..', '..', 'client', 'webpack-hot-middleware-client'), | ||
dev && !isServer && path.join(__dirname, '..', '..', 'client', 'on-demand-entries-client'), | ||
require.resolve(`../../client/next${dev ? '-dev' : ''}`) | ||
dev && !isServer && path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'webpack-hot-middleware-client'), | ||
dev && !isServer && path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'on-demand-entries-client'), | ||
path.join(NEXT_PROJECT_ROOT_DIST, 'client', (dev ? `next-dev` : 'next')) | ||
].filter(Boolean) | ||
} : {} | ||
|
||
|
@@ -102,17 +107,17 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer | |
resolve: { | ||
extensions: ['.js', '.jsx', '.json'], | ||
modules: [ | ||
nextNodeModulesDir, | ||
NEXT_PROJECT_ROOT_NODE_MODULES, | ||
'node_modules', | ||
...nodePathList // Support for NODE_PATH environment variable | ||
], | ||
alias: { | ||
next: nextDir | ||
next: NEXT_PROJECT_ROOT | ||
} | ||
}, | ||
resolveLoader: { | ||
modules: [ | ||
nextNodeModulesDir, | ||
NEXT_PROJECT_ROOT_NODE_MODULES, | ||
'node_modules', | ||
path.join(__dirname, 'loaders'), | ||
...nodePathList // Support for NODE_PATH environment variable | ||
|
@@ -122,14 +127,8 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer | |
rules: [ | ||
dev && !isServer && { | ||
test: /\.(js|jsx)$/, | ||
loader: 'hot-self-accept-loader', | ||
include: [ | ||
path.join(dir, 'pages'), | ||
nextPagesDir | ||
], | ||
options: { | ||
extensions: /\.(js|jsx)$/ | ||
} | ||
include: defaultLoaders.hotSelfAccept.options.include, | ||
use: defaultLoaders.hotSelfAccept | ||
}, | ||
{ | ||
test: /\.(js|jsx)$/, | ||
|
@@ -206,15 +205,13 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer | |
return true | ||
} | ||
|
||
// commons | ||
// If there are one or two pages, only move modules to common if they are | ||
// used in all of the pages. Otherwise, move modules used in at-least | ||
// 1/2 of the total pages into commons. | ||
if (totalPages <= 2) { | ||
return count >= totalPages | ||
} | ||
return count >= totalPages * 0.5 | ||
// commons end | ||
} | ||
}), | ||
// We use a manifest file in development to speed up HMR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// flow-typed signature: fbec9bc08efb50bade7bd6c2bab84e41 | ||
// flow-typed version: <<STUB>>/loader-utils_v1.1.0/flow_v0.73.0 | ||
|
||
/** | ||
* This is an autogenerated libdef stub for: | ||
* | ||
* 'loader-utils' | ||
* | ||
* Fill this stub out by replacing all the `any` types. | ||
* | ||
* Once filled out, we encourage you to share your work with the | ||
* community by sending a pull request to: | ||
* https://github.com/flowtype/flow-typed | ||
*/ | ||
|
||
declare module 'loader-utils' { | ||
declare module.exports: any; | ||
} | ||
|
||
/** | ||
* We include stubs for each file inside this npm package in case you need to | ||
* require those files directly. Feel free to delete any files that aren't | ||
* needed. | ||
*/ | ||
declare module 'loader-utils/lib/getCurrentRequest' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/getHashDigest' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/getOptions' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/getRemainingRequest' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/index' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/interpolateName' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/isUrlRequest' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/parseQuery' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/parseString' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/stringifyRequest' { | ||
declare module.exports: any; | ||
} | ||
|
||
declare module 'loader-utils/lib/urlToRequest' { | ||
declare module.exports: any; | ||
} | ||
|
||
// Filename aliases | ||
declare module 'loader-utils/lib/getCurrentRequest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/getCurrentRequest'>; | ||
} | ||
declare module 'loader-utils/lib/getHashDigest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/getHashDigest'>; | ||
} | ||
declare module 'loader-utils/lib/getOptions.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/getOptions'>; | ||
} | ||
declare module 'loader-utils/lib/getRemainingRequest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/getRemainingRequest'>; | ||
} | ||
declare module 'loader-utils/lib/index.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/index'>; | ||
} | ||
declare module 'loader-utils/lib/interpolateName.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/interpolateName'>; | ||
} | ||
declare module 'loader-utils/lib/isUrlRequest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/isUrlRequest'>; | ||
} | ||
declare module 'loader-utils/lib/parseQuery.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/parseQuery'>; | ||
} | ||
declare module 'loader-utils/lib/parseString.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/parseString'>; | ||
} | ||
declare module 'loader-utils/lib/stringifyRequest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/stringifyRequest'>; | ||
} | ||
declare module 'loader-utils/lib/urlToRequest.js' { | ||
declare module.exports: $Exports<'loader-utils/lib/urlToRequest'>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do the
indexOf
outside of the predicate to a variable and use that in hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How'd you mean 🤔