Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
29906bb
Module/nomodule implementation based on RFC 7563
janicklas-ralph Jun 27, 2019
2299129
Remove comment
janicklas-ralph Jul 2, 2019
0a4ea07
Fixing issue with building amp pages
janicklas-ralph Jul 2, 2019
aafa8d7
Fixing test cases for serverless mode
janicklas-ralph Jul 9, 2019
d722f52
Adding safari 10 nomodule fix. Preloading modern js by default
janicklas-ralph Jul 10, 2019
498a602
Fixing size-limit integration test
janicklas-ralph Jul 10, 2019
2ad8dd9
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 10, 2019
d0b95c7
Bug fix
janicklas-ralph Jul 10, 2019
c1e97a0
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 11, 2019
5ec94dc
Adding testcase for modern build
janicklas-ralph Jul 11, 2019
562f704
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 12, 2019
f795221
Trigger rebuild
janicklas-ralph Jul 12, 2019
3bc16ce
Setting default crossOrigin value
janicklas-ralph Jul 15, 2019
7871271
Moving modern config option inside experimental flag
janicklas-ralph Jul 16, 2019
8dc4c5d
Adding nomodule attribute to safari-fix script
janicklas-ralph Jul 16, 2019
028915c
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 16, 2019
7adf981
Changing safari10NomoduleFix default value to true
janicklas-ralph Jul 16, 2019
77e9805
Removing safari-fix flag
janicklas-ralph Jul 18, 2019
2ab5728
Changing .es6 to .module
janicklas-ralph Jul 18, 2019
8cf16e0
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 22, 2019
b6a4d11
Disable modern default
Timer Jul 23, 2019
75d473b
Merge branch 'canary' of github.com:zeit/next.js into canary
janicklas-ralph Jul 24, 2019
483c38c
Merge branch 'canary' of github.com:janicklas-ralph/next.js into canary
janicklas-ralph Jul 24, 2019
322852f
Removing default crossOrigin value. Setting modern flag to false by d…
janicklas-ralph Jul 24, 2019
8b209f6
Merge branch 'canary' into mnom
Timer Jul 24, 2019
f0bcc4a
Remove confusing defaults and mark required instead
Timer Jul 24, 2019
f4ff686
Adjust blacklist
Timer Jul 24, 2019
40057ce
Move behavior of page marking
Timer Jul 24, 2019
c06b8c1
Fixing childCompiler errors not being captured
janicklas-ralph Jul 24, 2019
51ee549
Tweak names
Timer Jul 24, 2019
4e60971
Merge branch 'canary' of github.com:janicklas-ralph/next.js into mnom
Timer Jul 24, 2019
b73c843
Revert
Timer Jul 24, 2019
2cdfe90
whoops
Timer Jul 24, 2019
70f8a67
Fixing bug with page-loader.js
janicklas-ralph Jul 24, 2019
ebcdde4
Merge branch 'canary' of github.com:janicklas-ralph/next.js into canary
janicklas-ralph Jul 24, 2019
b5fa8bd
Changing modern babel cache name
janicklas-ralph Jul 24, 2019
1a99dd4
Rename helper
Timer Jul 24, 2019
aefd501
Iterate over both bundles
Timer Jul 25, 2019
46fed08
Correctly clamp bundle sizes
Timer Jul 25, 2019
58082f6
Revert test
Timer Jul 25, 2019
c1854f7
Add modern mode tests
Timer Jul 25, 2019
d86a4c5
Fix test
Timer Jul 25, 2019
f1ba3f5
test
Timer Jul 25, 2019
8e009c2
test2
Timer Jul 25, 2019
248d775
Merge branch 'canary' into canary
Timer Jul 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const defaultConfig: { [key: string]: any } = {
asyncToPromises: false,
documentMiddleware: false,
publicDirectory: false,
modern: false,
},
serverRuntimeConfig: {},
publicRuntimeConfig: {},
Expand Down
13 changes: 13 additions & 0 deletions packages/next/build/babel/plugins/next-page-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ export default function nextPageConfig({
t.returnStatement(t.stringLiteral(inlineGipIdentifier)),
])
},
// handles class { static async getInitialProps() {} }
ClassMethod(path, state: ConfigState) {
if (!state.setupInlining) return
if (
(path.node.key && (path.node.key as BabelTypes.Identifier).name) !==
'getInitialProps'
)
return

path.node.body = t.blockStatement([
t.returnStatement(t.stringLiteral(inlineGipIdentifier)),
])
},
},
}
}
1 change: 0 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
getSpecifiedPages,
printTreeView,
PageInfo,
isPageStatic,
hasCustomAppGetInitialProps,
} from './utils'
import getBaseWebpackConfig from './webpack-config'
Expand Down
28 changes: 26 additions & 2 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin'
import { ServerlessPlugin } from './webpack/plugins/serverless-plugin'
import { SharedRuntimePlugin } from './webpack/plugins/shared-runtime-plugin'
import { TerserPlugin } from './webpack/plugins/terser-webpack-plugin/src/index'
import NextEsmPlugin from './webpack/plugins/next-esm-plugin'

type ExcludesFalse = <T>(x: T | false) => x is T

Expand Down Expand Up @@ -175,6 +176,11 @@ export default async function getBaseWebpackConfig(

const devtool = dev ? 'cheap-module-source-map' : false

const crossOrigin =
!config.crossOrigin && config.experimental.modern
? 'anonymous'
: config.crossOrigin

let webpackConfig: webpack.Configuration = {
devtool,
mode: webpackMode,
Expand Down Expand Up @@ -365,7 +371,7 @@ export default async function getBaseWebpackConfig(
? `${dev ? '[name]' : '[name].[contenthash]'}.js`
: `static/chunks/${dev ? '[name]' : '[name].[contenthash]'}.js`,
strictModuleExceptionHandling: true,
crossOriginLoading: config.crossOrigin,
crossOriginLoading: crossOrigin,
futureEmitAssets: !dev,
webassemblyModuleFilename: 'static/wasm/[modulehash].wasm',
},
Expand Down Expand Up @@ -444,7 +450,7 @@ export default async function getBaseWebpackConfig(
}
}, {}),
'process.env.NODE_ENV': JSON.stringify(webpackMode),
'process.crossOrigin': JSON.stringify(config.crossOrigin),
'process.crossOrigin': JSON.stringify(crossOrigin),
'process.browser': JSON.stringify(!isServer),
// This is used in client/dev-error-overlay/hot-dev-client.js to replace the dist directory
...(dev && !isServer
Expand All @@ -455,6 +461,7 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
config.exportTrailingSlash
),
'process.env.__NEXT_MODERN_BUILD': config.experimental.modern && !dev,
...(isServer
? {
// Allow browser-only code to be eliminated
Expand Down Expand Up @@ -568,6 +575,23 @@ export default async function getBaseWebpackConfig(
silent: true,
formatter: 'codeframe',
}),
config.experimental.modern &&
!isServer &&
!dev &&
new NextEsmPlugin({
filename: (getFileName: Function | string) => (...args: any[]) => {
const name =
typeof getFileName === 'function'
? getFileName(...args)
: getFileName

return name.includes('.js')
? name.replace(/\.js$/, '.module.js')
: args[0].chunk.name.replace(/\.js$/, '.module.js')
},
chunkFilename: (inputChunkName: string) =>
inputChunkName.replace(/\.js$/, '.module.js'),
}),
].filter((Boolean as any) as ExcludesFalse),
}

Expand Down
73 changes: 62 additions & 11 deletions packages/next/build/webpack/loaders/next-babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@ import babelLoader from 'babel-loader'

// increment 'c' to invalidate cache
const cacheKey = 'babel-cache-' + 'c' + '-'
const nextBabelPreset = require('../../babel/preset')

const getModernOptions = (babelOptions = {}) => {
const presetEnvOptions = Object.assign({}, babelOptions['preset-env'])
const transformRuntimeOptions = Object.assign(
{},
babelOptions['transform-runtime'],
{ regenerator: false }
)

presetEnvOptions.targets = {
esmodules: true
}
presetEnvOptions.exclude = [
...(presetEnvOptions.exclude || []),
// Blacklist accidental inclusions
'transform-regenerator',
'transform-async-to-generator'
]

return {
...babelOptions,
'preset-env': presetEnvOptions,
'transform-runtime': transformRuntimeOptions
}
}

const nextBabelPresetModern = presetOptions => context =>
nextBabelPreset(context, getModernOptions(presetOptions))

module.exports = babelLoader.custom(babel => {
const presetItem = babel.createConfigItem(require('../../babel/preset'), {
const presetItem = babel.createConfigItem(nextBabelPreset, {
type: 'preset'
})
const applyCommonJs = babel.createConfigItem(
Expand All @@ -24,7 +53,8 @@ module.exports = babelLoader.custom(babel => {
customOptions (opts) {
const custom = {
isServer: opts.isServer,
asyncToPromises: opts.asyncToPromises
asyncToPromises: opts.asyncToPromises,
isModern: opts.isModern
}
const filename = join(opts.cwd, 'noop.js')
const loader = Object.assign(
Expand All @@ -35,6 +65,7 @@ module.exports = babelLoader.custom(babel => {
cacheIdentifier:
cacheKey +
(opts.isServer ? '-server' : '') +
(opts.isModern ? '-modern' : '') +
JSON.stringify(
babel.loadPartialConfig({
filename,
Expand All @@ -53,13 +84,14 @@ module.exports = babelLoader.custom(babel => {
delete loader.asyncToPromises
delete loader.cache
delete loader.distDir
delete loader.isModern
return { loader, custom }
},
config (
cfg,
{
source,
customOptions: { isServer, asyncToPromises }
customOptions: { isServer, asyncToPromises, isModern }
}
) {
const { cwd } = cfg.options
Expand Down Expand Up @@ -104,7 +136,26 @@ module.exports = babelLoader.custom(babel => {
options.plugins.push(nextDataPlugin)
}

if (asyncToPromises) {
if (isModern) {
const nextPreset = options.presets.find(
preset => preset && preset.value === nextBabelPreset
) || { options: {} }

const additionalPresets = options.presets.filter(
preset => preset !== nextPreset
)

const presetItemModern = babel.createConfigItem(
nextBabelPresetModern(nextPreset.options),
{
type: 'preset'
}
)

options.presets = [...additionalPresets, presetItemModern]
}

if (!isModern && asyncToPromises) {
const asyncToPromisesPlugin = babel.createConfigItem(
[
'babel-plugin-transform-async-to-promises',
Expand All @@ -128,13 +179,13 @@ module.exports = babelLoader.custom(babel => {
return preset[0] === require('@babel/preset-env').default
})
if (babelPresetEnv) {
babelPresetEnv[1].exclude = (options.presets[0][1].exclude || [])
.concat([
'transform-typeof-symbol',
'transform-regenerator',
'transform-async-to-generator'
])
.filter('transform-typeof-symbol')
babelPresetEnv[1].exclude = (
options.presets[0][1].exclude || []
).concat([
'transform-typeof-symbol',
'transform-regenerator',
'transform-async-to-generator'
])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ export class DropClientPage implements Plugin {
const page = '/' + cleanAssetKey.split('pages/')[1]
const pageNoExt = page.split(extname(page))[0]

this.ampPages.add(pageNoExt.replace(/\/index$/, '') || '/')
delete compilation.assets[assetKey]

// Detect being re-ran through a child compiler and don't re-mark the
// page as AMP
if (!pageNoExt.endsWith('.module')) {
this.ampPages.add(pageNoExt.replace(/\/index$/, '') || '/')
}
}
})
})
Expand Down
Loading