Update to make sure AMP only bundles are always removed in pro… (#11527)
This commit is contained in:
parent
fa5da6d220
commit
d61eced9a6
4 changed files with 30 additions and 1 deletions
|
@ -547,6 +547,25 @@ export default async function build(dir: string, conf = null): Promise<void> {
|
|||
hybridAmpPages.add(page)
|
||||
}
|
||||
|
||||
if (result.isAmpOnly) {
|
||||
// ensure all AMP only bundles got removed
|
||||
try {
|
||||
await fsUnlink(
|
||||
path.join(
|
||||
distDir,
|
||||
'static',
|
||||
buildId,
|
||||
'pages',
|
||||
actualPage + '.js'
|
||||
)
|
||||
)
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.hasStaticProps) {
|
||||
ssgPages.add(page)
|
||||
isSsg = true
|
||||
|
|
|
@ -665,6 +665,7 @@ export async function isPageStatic(
|
|||
runtimeEnvConfig: any
|
||||
): Promise<{
|
||||
isStatic?: boolean
|
||||
isAmpOnly?: boolean
|
||||
isHybridAmp?: boolean
|
||||
hasServerProps?: boolean
|
||||
hasStaticProps?: boolean
|
||||
|
@ -756,6 +757,7 @@ export async function isPageStatic(
|
|||
return {
|
||||
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
|
||||
isHybridAmp: config.amp === 'hybrid',
|
||||
isAmpOnly: config.amp === true,
|
||||
prerenderRoutes,
|
||||
prerenderFallback,
|
||||
hasStaticProps,
|
||||
|
|
8
test/integration/amphtml/pages/another-amp.js
Normal file
8
test/integration/amphtml/pages/another-amp.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { useAmp } from 'next/amp'
|
||||
|
||||
const config = {
|
||||
amp: true,
|
||||
}
|
||||
|
||||
export default () => (useAmp() ? 'AMP mode' : 'Normal mode')
|
||||
export { config }
|
|
@ -66,7 +66,7 @@ describe('AMP Usage', () => {
|
|||
|
||||
it('should not output client pages for AMP only', async () => {
|
||||
const buildId = readFileSync(join(appDir, '.next/BUILD_ID'), 'utf8')
|
||||
const ampOnly = ['only-amp', 'root-hmr']
|
||||
const ampOnly = ['only-amp', 'root-hmr', 'another-amp']
|
||||
for (const pg of ampOnly) {
|
||||
expect(() =>
|
||||
accessSync(join(appDir, '.next/static', buildId, 'pages', pg + '.js'))
|
||||
|
|
Loading…
Reference in a new issue