Skip to content

Commit

Permalink
Add asset relocator for production mode of serverless trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Aug 5, 2019
1 parent e6e0366 commit 8404f1d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default async function getBaseWebpackConfig(
const isServerlessTrace = target === 'experimental-serverless-trace'
const isLikeServerless = isServerless || isServerlessTrace

const isProductionServerlessTrace = isServerlessTrace && !dev && isServer

const outputDir = isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY
const outputPath = path.join(distDir, isServer ? outputDir : '')
const totalPages = Object.keys(entrypoints).length
Expand Down Expand Up @@ -403,10 +405,40 @@ export default async function getBaseWebpackConfig(
...nodePathList, // Support for NODE_PATH environment variable
],
},
...(isProductionServerlessTrace
? {
// `@zeit/webpack-asset-relocator-loader` will relocated all assets
// so we can't let webpack mock this to `/` & `/index.js`.
//
// This is not enabled for `target: 'serverless'` for backwards
// compatibility reasons.
node: { __dirname: false, __filename: false },
}
: undefined),
// @ts-ignore this is filtered
module: {
strictExportPresence: true,
rules: [
// This loader relocates all build assets into a new folder since we
// change the emitted path structure during bundling.
//
// This is not enabled for `target: 'serverless'` for backwards
// compatibility reasons.
isProductionServerlessTrace && {
// These extensions have been transformed into traditional JavaScript
// by prior loaders.
test: /\.(tsx|ts|js|mjs|jsx|node)$/,
parser: { amd: false },
use: {
loader: '@zeit/webpack-asset-relocator-loader',
options: {
outputAssetBase: 'assets',
existingAssetNames: [],
wrapperCompatibility: false,
production: true,
},
},
},
(selectivePageBuilding || config.experimental.terserLoader) &&
!isServer && {
test: /\.(js|mjs|jsx)$/,
Expand Down
1 change: 1 addition & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@babel/preset-typescript": "7.3.3",
"@babel/runtime": "7.4.5",
"@babel/runtime-corejs2": "7.4.5",
"@zeit/webpack-asset-relocator-loader": "0.6.2",
"amphtml-validator": "1.0.23",
"async-sema": "3.0.0",
"autodll-webpack-plugin": "0.4.2",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,13 @@
dependencies:
"@babel/preset-typescript" "^7.0.0"

"@zeit/[email protected]":
version "0.6.2"
resolved "https://registry.yarnpkg.com/@zeit/webpack-asset-relocator-loader/-/webpack-asset-relocator-loader-0.6.2.tgz#b15353d8578562f299eddb94d4b771297acc0487"
integrity sha512-IUz2YvFAv03LHP4dhjHqG549ecZhdp7KU8B+vGfJRgcDzvlCmc9CA1YcYfJHVO96U8dU5z85RIysr2whYUXmgQ==
dependencies:
sourcemap-codec "^1.4.4"

JSONStream@^1.0.4, JSONStream@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -12241,6 +12248,11 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=

sourcemap-codec@^1.4.4:
version "1.4.6"
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz#e30a74f0402bad09807640d39e971090a08ce1e9"
integrity sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg==

spawn-sync@^1.0.15:
version "1.0.15"
resolved "https://registry.yarnpkg.com/spawn-sync/-/spawn-sync-1.0.15.tgz#b00799557eb7fb0c8376c29d44e8a1ea67e57476"
Expand Down

0 comments on commit 8404f1d

Please sign in to comment.