Unverified Commit ceb60b65 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

revert nccing webpack (#7189)

parent ab8620d6
import webpack, {Stats} from 'next/dist/compiled/webpack'
import webpack, {Stats} from 'webpack'
export type CompilerResult = {
errors: Error[]
......
import fs from 'fs'
import nodeLibsBrowser from 'node-libs-browser'
import {
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_WEBPACK,
......@@ -9,7 +8,7 @@ import {
import resolve from 'next/dist/compiled/resolve/index.js'
import path from 'path'
import { promisify } from 'util'
import webpack from 'next/dist/compiled/webpack'
import webpack from 'webpack'
import {
DOT_NEXT_ALIAS,
......@@ -76,20 +75,6 @@ export default async function getBaseWebpackConfig(
},
}
// manually map node-libs-browser to fix ncced webpack resolving
const nodeLibs: any = {}
if (!isServer) {
for (const key in nodeLibsBrowser) {
if (key === 'module') continue
const lib = nodeLibsBrowser[key]
if (typeof lib === 'string') {
nodeLibs[key] = lib
}
}
}
// Support for NODE_PATH
const nodePathList = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
......@@ -140,7 +125,6 @@ export default async function getBaseWebpackConfig(
...nodePathList, // Support for NODE_PATH environment variable
],
alias: {
...nodeLibs,
// These aliases make sure the wrapper module is not included in the bundles
// Which makes bundles slightly smaller, but also skips parsing a module that we know will result in this alias
'next/head': 'next-server/dist/lib/head.js',
......@@ -165,7 +149,6 @@ export default async function getBaseWebpackConfig(
}
let webpackConfig: webpack.Configuration = {
node: false, // handle node libs manually
mode: webpackMode,
devtool: dev || debug ? 'cheap-module-source-map' : false,
name: isServer ? 'server' : 'client',
......@@ -425,16 +408,6 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
config.experimental.exportTrailingSlash
),
...(isServer ? {} : { 'global': 'window' }),
'process': {
env: {},
argv: [],
browser: !isServer,
pid: 1,
execPath: 'browser',
platform: 'browser',
features: {},
}
}),
!isServer &&
new ReactLoadablePlugin({
......
import {loader} from 'next/dist/compiled/webpack'
import {loader} from 'webpack'
import loaderUtils from 'loader-utils'
export type ClientPagesLoaderOptions = {
......
import {loader} from 'next/dist/compiled/webpack'
import {loader} from 'webpack'
import hash from 'string-hash'
import {basename} from 'path'
const nextDataLoader: loader.Loader = function (source) {
......
import loaderUtils from 'loader-utils'
import { loader } from 'next/dist/compiled/webpack'
import { loader } from 'webpack'
import minify from '../plugins/terser-webpack-plugin/src/minify'
const nextMiniferLoader: loader.Loader = function(source) {
......
import {loader} from 'next/dist/compiled/webpack'
import {loader} from 'webpack'
import {join} from 'path'
import {parse} from 'querystring'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next-server/constants'
......@@ -59,8 +59,8 @@ const nextServerlessLoader: loader.Loader = function () {
{
Component,
dataOnly: req.headers && (req.headers.accept || '').indexOf('application/amp.bind+json') !== -1,
},
options,
},
options,
))
return result
} catch (err) {
......
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
import path from 'path'
......
import { Compiler } from 'next/dist/compiled/webpack'
import { Compiler } from 'webpack'
import { RawSource } from 'webpack-sources'
import {
BUILD_MANIFEST,
......
......@@ -4,7 +4,7 @@ import { CLIENT_STATIC_FILES_RUNTIME_MAIN } from 'next-server/constants'
import { EOL } from 'os'
import path from 'path'
import { parse } from 'querystring'
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
type StringDictionary = { [pageName: string]: string[] }
const manifest: {
......
import { Compiler } from 'next/dist/compiled/webpack'
import { Compiler } from 'webpack'
// This plugin mirrors webpack 3 `filename` and `chunkfilename` behavior
// This fixes https://github.com/webpack/webpack/issues/6598
// This plugin is based on https://github.com/researchgate/webpack/commit/2f28947fa0c63ccbb18f39c0098bd791a2c37090
......
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
export class HashedChunkIdsPlugin implements Plugin {
......
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
import { extname } from 'path'
// Prevents outputting client pages when they are not needed
......
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
import { realpathSync } from 'fs'
function deleteCache (path: string) {
......
import { join, resolve, relative, dirname } from 'path'
import { Compiler } from 'next/dist/compiled/webpack'
import { Compiler } from 'webpack'
// This plugin modifies the require-ensure code generated by Webpack
// to work with Next.js SSR
......
import webpack from 'next/dist/compiled/webpack'
import webpack from 'webpack'
import { RawSource } from 'webpack-sources'
import { join, relative, dirname } from 'path'
import { IS_BUNDLED_PAGE_REGEX } from 'next-server/constants'
......
import {Compiler, Plugin} from 'next/dist/compiled/webpack'
import {Compiler, Plugin} from 'webpack'
import { RawSource } from 'webpack-sources'
import { PAGES_MANIFEST, ROUTE_NAME_REGEX } from 'next-server/constants'
......
......@@ -22,7 +22,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
// Modified to strip out unneeded results for Next's specific use case
import url from 'url'
import { Compiler, compilation } from 'next/dist/compiled/webpack'
import { Compiler, compilation } from 'webpack'
function buildManifest (compiler: Compiler, compilation: compilation.Compilation) {
let context = compiler.options.context
......
import { Compiler } from 'next/dist/compiled/webpack'
import { connectChunkAndModule } from 'next/dist/compiled/webpack/lib/GraphHelpers'
import { Compiler } from 'webpack'
import { connectChunkAndModule } from 'webpack/lib/GraphHelpers'
/**
* Makes sure there are no dynamic chunks when the target is serverless
......
import { Compiler, Plugin } from 'next/dist/compiled/webpack'
import { Compiler, Plugin } from 'webpack'
export class SharedRuntimePlugin implements Plugin {
apply(compiler: Compiler) {
......
......@@ -4,7 +4,7 @@
import stringHash from 'string-hash'
import { SourceMapConsumer } from 'source-map'
import { SourceMapSource, RawSource } from 'webpack-sources'
import { RequestShortener } from 'next/dist/compiled/webpack';
import { RequestShortener } from 'webpack';
import TaskRunner from './TaskRunner'
const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/
......
......@@ -2,7 +2,7 @@ import { join } from 'path'
import { promisify } from 'util'
import fs from 'fs'
import { IS_BUNDLED_PAGE_REGEX } from 'next-server/constants'
import {Compiler} from 'next/dist/compiled/webpack'
import {Compiler} from 'webpack'
const unlink = promisify(fs.unlink)
......
......@@ -55,6 +55,7 @@
]
},
"dependencies": {
"autodll-webpack-plugin": "0.4.2",
"@babel/core": "7.1.2",
"@babel/plugin-proposal-class-properties": "7.1.0",
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
......@@ -80,7 +81,6 @@
"loader-utils": "1.1.0",
"mkdirp": "0.5.1",
"next-server": "8.1.1-canary.18",
"node-libs-browser": "2.2.0",
"prop-types": "15.6.2",
"prop-types-exact": "1.2.0",
"react-error-overlay": "5.1.4",
......@@ -95,6 +95,9 @@
"tty-aware-progress": "1.0.3",
"unfetch": "4.1.0",
"url": "0.11.0",
"webpack": "4.29.0",
"webpack-dev-middleware": "3.6.0",
"webpack-hot-middleware": "2.24.3",
"webpack-sources": "1.3.0",
"worker-farm": "1.5.2"
},
......@@ -128,17 +131,13 @@
"@types/webpack-sources": "0.1.5",
"@zeit/ncc": "0.15.2",
"arg": "4.1.0",
"autodll-webpack-plugin": "0.4.2",
"babel-plugin-dynamic-import-node": "2.2.0",
"nanoid": "2.0.1",
"resolve": "1.5.0",
"taskr": "1.1.0",
"text-table": "0.2.0",
"typescript": "3.1.6",
"unistore": "3.2.1",
"webpack": "4.29.0",
"webpack-dev-middleware": "3.6.0",
"webpack-hot-middleware": "2.24.3"
"unistore": "3.2.1"
},
"engines": {
"node": ">= 8.0.0"
......
import { relative as relativePath, join, normalize, sep } from 'path'
import WebpackDevMiddleware from 'next/dist/compiled/webpack-dev-middleware'
import WebpackHotMiddleware from 'next/dist/compiled/webpack-hot-middleware'
import WebpackDevMiddleware from 'webpack-dev-middleware'
import WebpackHotMiddleware from 'webpack-hot-middleware'
import errorOverlayMiddleware from './lib/error-overlay-middleware'
import onDemandEntryHandler, { normalizePage } from './on-demand-entry-handler'
import webpack from 'next/dist/compiled/webpack'
import webpack from 'webpack'
import getBaseWebpackConfig from '../build/webpack-config'
import { IS_BUNDLED_PAGE_REGEX, ROUTE_NAME_REGEX, BLOCKED_PAGES, CLIENT_STATIC_FILES_RUNTIME_AMP } from 'next-server/constants'
import { NEXT_PROJECT_ROOT_DIST_CLIENT } from '../lib/constants'
......
import webpack from 'next/dist/compiled/webpack'
import DynamicEntryPlugin from 'webpack/lib/DynamicEntryPlugin'
import { EventEmitter } from 'events'
import { join, posix } from 'path'
import { parse } from 'url'
......@@ -17,8 +17,7 @@ const BUILT = Symbol('built')
// Based on https://github.com/webpack/webpack/blob/master/lib/DynamicEntryPlugin.js#L29-L37
function addEntry (compilation, context, name, entry) {
return new Promise((resolve, reject) => {
const dep = webpack.SingleEntryPlugin.createDependency(entry, name)
const dep = DynamicEntryPlugin.createDependency(entry, name)
compilation.addEntry(context, dep, name, (err) => {
if (err) return reject(err)
resolve()
......@@ -29,10 +28,13 @@ function addEntry (compilation, context, name, entry) {
export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
buildId,
dir,
distDir,
reload,
pageExtensions,
maxInactiveAge,
pagesBufferLength
pagesBufferLength,
publicRuntimeConfig,
serverRuntimeConfig
}) {
const pagesDir = join(dir, 'pages')
const { compilers } = multiCompiler
......@@ -59,7 +61,7 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
}
entries[page].status = BUILDING
return addEntry(compilation, compiler.context, name, compiler.name === 'client' ? `next-client-pages-loader?${stringify({ page, absolutePagePath })}!` : absolutePagePath)
return addEntry(compilation, compiler.context, name, [compiler.name === 'client' ? `next-client-pages-loader?${stringify({ page, absolutePagePath })}!` : absolutePagePath])
})
return Promise.all(allEntries)
......
......@@ -45,87 +45,6 @@ const babelServerOpts = {
]
}
// eslint-disable-next-line camelcase
export async function ncc_webpack (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack')))
.ncc({
packageName: 'webpack'
})
.target('dist/compiled/webpack')
notify('Compiled webpack')
}
// eslint-disable-next-line camelcase
export async function ncc_webpack_module (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack/buildin/module')))
.ncc()
.target('dist/compiled/webpack/buildin')
notify('Compiled webpack/buildin/module')
}
// eslint-disable-next-line camelcase
export async function ncc_webpack_harmony_module (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack/buildin/harmony-module')))
.ncc()
.target('dist/compiled/webpack/buildin')
notify('Compiled webpack/buildin/harmony-module')
}
// eslint-disable-next-line camelcase
export async function ncc_webpack_graph_helpers (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack/lib/GraphHelpers')))
.ncc()
.target('dist/compiled/webpack/lib')
notify('Compiled webpack/lib/GraphHelpers')
}
// eslint-disable-next-line camelcase
export async function ncc_webpack_hot_middleware (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack-hot-middleware')))
.ncc({
externals: ['chokidar', 'webpack'],
packageName: 'webpack-hot-middleware'
})
.target('dist/compiled/webpack-hot-middleware')
notify('Compiled webpack-hot-middleware')
}
// eslint-disable-next-line camelcase
export async function ncc_autodll_webpack_plugin (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('autodll-webpack-plugin')))
.ncc({
externals: ['chokidar', 'webpack'],
packageName: 'autodll-webpack-plugin'
})
.target('dist/compiled/autodll-webpack-plugin')
notify('Compiled autodll-webpack-plugin')
}
// eslint-disable-next-line camelcase
export async function ncc_webpack_dev_middleware (task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('webpack-dev-middleware')))
.ncc({
externals: ['chokidar', 'webpack'],
packageName: 'webpack-dev-middleware'
})
.target('dist/compiled/webpack-dev-middleware')
notify('Compiled webpack-dev-middleware')
}
// eslint-disable-next-line camelcase
export async function ncc_arg (task, opts) {
await task
......@@ -167,7 +86,7 @@ export async function ncc_text_table (task, opts) {
}
export async function precompile (task) {
await task.parallel(['ncc_webpack', 'ncc_webpack_module', 'ncc_webpack_harmony_module', 'ncc_webpack_graph_helpers', 'ncc_webpack_hot_middleware', 'ncc_autodll_webpack_plugin', 'ncc_webpack_dev_middleware', 'ncc_unistore', 'ncc_resolve', 'ncc_arg', 'ncc_nanoid', 'ncc_text_table'])
await task.parallel(['ncc_unistore', 'ncc_resolve', 'ncc_arg', 'ncc_nanoid', 'ncc_text_table'])
}
export async function compile (task) {
......
// Type definitions for loader-utils 1.1
// Project: https://github.com/webpack/loader-utils#readme
// Definitions by: Gyusun Yeom <https://github.com/Perlmint>
// Totooria Hyperion <https://github.com/TotooriaHyperion>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
declare module "loader-utils" {
import { loader } from 'next/dist/compiled/webpack';
export interface InterpolateOption {
context?: string;
content?: string | Buffer;
regExp?: string | RegExp;
}
export interface OptionObject {
[key: string]: any;
}
export type HashType = "sha1" | "md5" | "sha256" | "sha512";
export type DigestType = "hex" | "base26" | "base32" | "base36" | "base49" | "base52" | "base58" | "base62" | "base64";
export function getOptions(loaderContext: loader.LoaderContext): OptionObject;
export function parseQuery(optionString: string): OptionObject;
export function stringifyRequest(loaderContext: loader.LoaderContext, resource: string): string;
export function getRemainingRequest(loaderContext: loader.LoaderContext): string;
export function getCurrentRequest(loaderContext: loader.LoaderContext): string;
export function isUrlRequest(url: string, root?: string): boolean;
export function parseString(str: string): string;
export function urlToRequest(url: string, root?: string): string;
export function interpolateName(loaderContext: loader.LoaderContext, name: string, options?: any): string;
export function getHashDigest(buffer: Buffer, hashType: HashType, digestType: DigestType, maxLength: number): string;
}
......@@ -5,16 +5,6 @@ declare module 'webpack/lib/GraphHelpers';
declare module 'unfetch';
declare module 'styled-jsx/server';
declare module 'node-libs-browser' {
const nodeLibs: any
export = nodeLibs;
}
declare module 'next/dist/compiled/webpack/lib/GraphHelpers' {
export const connectChunkAndModule: any
}
declare module 'next/dist/compiled/nanoid/index.js' {
function nanoid(size?: number): string;
......@@ -67,7 +57,7 @@ declare module 'next/dist/compiled/arg/index.js' {
}
declare module 'autodll-webpack-plugin' {
import webpack from 'next/dist/compiled/webpack'
import webpack from 'webpack'
class AutoDllPlugin implements webpack.Plugin {
constructor(settings?: {
inject?: boolean,
......
......@@ -21,7 +21,7 @@
/// <reference types="node" />
declare module 'next/dist/compiled/webpack' {
declare module 'webpack' {
import { Tapable, HookMap,
SyncBailHook, SyncHook, SyncLoopHook, SyncWaterfallHook,
AsyncParallelBailHook, AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } from 'tapable';
......
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const webpack = require('next/dist/compiled/webpack')
const path = require('path')
module.exports = withCSS(withSass({
onDemandEntries: {
......@@ -18,7 +17,7 @@ module.exports = withCSS(withSass({
env: {
customVar: 'hello'
},
webpack (config, { buildId }) {
webpack (config, { buildId, webpack }) {
// When next-css is `npm link`ed we have to solve loaders from the project root
const nextLocation = path.join(require.resolve('next/package.json'), '../')
const nextCssNodeModulesLocation = path.join(
......
......@@ -8762,7 +8762,7 @@ node-int64@^0.4.0:
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
integrity sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=
node-libs-browser@2.2.0, node-libs-browser@^2.0.0:
node-libs-browser@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.2.0.tgz#c72f60d9d46de08a940dedbb25f3ffa2f9bbaa77"
integrity sha512-5MQunG/oyOaBdttrL40dA7bUfPORLRWMUJLQtMg7nluxUvk5XwnLdL9twQHFAjRx/y7mIMkLKT9++qPbbk6BZA==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment