Skip to content

Commit

Permalink
Revert "ncc Webpack build redux (#7628)"
Browse files Browse the repository at this point in the history
This reverts commit e85a517.
  • Loading branch information
Timer committed Jun 24, 2019
1 parent a30870b commit 31b3106
Show file tree
Hide file tree
Showing 38 changed files with 87 additions and 239 deletions.
14 changes: 0 additions & 14 deletions packages/next/build/bundles/autodll-webpack-plugin.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/next/build/bundles/bundled-webpack.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/build/bundles/webpack-DynamicEntryPlugin.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/build/bundles/webpack-GraphHelpers.js

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/build/bundles/webpack.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/next/build/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import webpack, { Stats } from 'next/dist/compiled/webpack.js'
import webpack, { Stats } from 'webpack'

export type CompilerResult = {
errors: Error[]
Expand Down
7 changes: 3 additions & 4 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.js'
import webpack from 'webpack'

import {
DOT_NEXT_ALIAS,
Expand All @@ -22,6 +22,7 @@ import { AllModulesIdentifiedPlugin } from './webpack/plugins/all-modules-identi
import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import { ChunkGraphPlugin } from './webpack/plugins/chunk-graph-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { importAutoDllPlugin } from './webpack/plugins/dll-import'
import { HashedChunkIdsPlugin } from './webpack/plugins/hashed-chunk-ids-plugin'
import { DropClientPage } from './webpack/plugins/next-drop-client-page-plugin'
import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import'
Expand Down Expand Up @@ -481,9 +482,7 @@ export default async function getBaseWebpackConfig(
]

if (!isServer) {
const AutoDllPlugin = require('next/dist/compiled/autodll-webpack-plugin')(
distDir
)
const AutoDllPlugin = importAutoDllPlugin({ distDir })
devPlugins.push(
new AutoDllPlugin({
filename: '[name]_[hash].js',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loader } from 'next/dist/compiled/webpack.js'
import { loader } from 'webpack'
import loaderUtils from 'loader-utils'

export type ClientPagesLoaderOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-data-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loader } from 'next/dist/compiled/webpack.js'
import { loader } from 'webpack'
import hash from 'string-hash'
import { basename } from 'path'
const nextDataLoader: loader.Loader = function(source) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-minify-loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import loaderUtils from 'loader-utils'
import { loader } from 'next/dist/compiled/webpack.js'
import { loader } from 'webpack'
import minify from '../plugins/terser-webpack-plugin/src/minify'

const nextMiniferLoader: loader.Loader = function(source) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loader } from 'next/dist/compiled/webpack.js'
import { loader } from 'webpack'
import { join } from 'path'
import { parse } from 'querystring'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next-server/constants'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/noop-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loader } from 'next/dist/compiled/webpack.js'
import { loader } from 'webpack'

const NoopLoader: loader.Loader = source => source
export default NoopLoader
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
import path from 'path'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler } from 'next/dist/compiled/webpack.js'
import { Compiler } from 'webpack'
import { RawSource } from 'webpack-sources'
import {
BUILD_MANIFEST,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/plugins/chunk-graph-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.js'
import { Compiler, Plugin } from 'webpack'

type StringDictionary = { [pageName: string]: string[] }
const manifest: {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/plugins/chunk-names-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler } from 'next/dist/compiled/webpack.js'
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
Expand Down
23 changes: 23 additions & 0 deletions packages/next/build/webpack/plugins/dll-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'path'

export function importAutoDllPlugin({ distDir }: { distDir: string }) {
const autodllPaths = path.join(
path.dirname(require.resolve('autodll-webpack-plugin')),
'paths.js'
)
require(autodllPaths)

const autodllCachePath = path.resolve(
path.join(distDir, 'cache', 'autodll-webpack-plugin')
)
require.cache[autodllPaths] = Object.assign({}, require.cache[autodllPaths], {
exports: Object.assign({}, require.cache[autodllPaths].exports, {
cacheDir: autodllCachePath,
getManifestPath: (hash: string) => (bundleName: string) =>
path.resolve(autodllCachePath, hash, `${bundleName}.manifest.json`),
}),
})

const AutoDllPlugin = require('autodll-webpack-plugin')
return AutoDllPlugin
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import { NormalizedMessage } from 'fork-ts-checker-webpack-plugin/lib/NormalizedMessage'
import webpack from 'next/dist/compiled/webpack.js'
import webpack from 'webpack'

export function Apply(compiler: webpack.Compiler) {
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler as any)
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler)

let additionalFiles: string[] = []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'

export class HashedChunkIdsPlugin implements Plugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'
import { extname } from 'path'

// Prevents outputting client pages when they are not needed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'
import { realpathSync } from 'fs'

function deleteCache(path: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/plugins/nextjs-ssr-import.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, resolve, relative, dirname } from 'path'
import { Compiler } from 'next/dist/compiled/webpack.js'
import { Compiler } from 'webpack'

// This plugin modifies the require-ensure code generated by Webpack
// to work with Next.js SSR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import webpack from 'next/dist/compiled/webpack.js'
import webpack from 'webpack'
import { RawSource } from 'webpack-sources'
import { join, relative, dirname } from 'path'
import { IS_BUNDLED_PAGE_REGEX } from 'next-server/constants'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'
import { RawSource } from 'webpack-sources'
import {
PAGES_MANIFEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.js'
import { Compiler, compilation } from 'webpack'

function buildManifest(
compiler: Compiler,
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack/plugins/serverless-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Compiler } from 'next/dist/compiled/webpack.js'
import { connectChunkAndModule } from 'next/dist/compiled/webpack-GraphHelpers'
import { Compiler } from 'webpack'
import { connectChunkAndModule } from 'webpack/lib/GraphHelpers'

/**
* Makes sure there are no dynamic chunks when the target is serverless
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler, Plugin } from 'next/dist/compiled/webpack.js'
import { Compiler, Plugin } from 'webpack'

export class SharedRuntimePlugin implements Plugin {
apply(compiler: Compiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.js'
import { RequestShortener } from 'webpack'
import TaskRunner from './TaskRunner'

const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.js'
import { Compiler } from 'webpack'

const unlink = promisify(fs.unlink)

Expand Down
13 changes: 6 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@babel/runtime-corejs2": "7.4.5",
"amphtml-validator": "1.0.23",
"async-sema": "3.0.0",
"autodll-webpack-plugin": "0.4.2",
"babel-core": "7.0.0-bridge.0",
"babel-loader": "8.0.6",
"babel-plugin-react-require": "3.0.0",
Expand All @@ -81,7 +82,6 @@
"loader-utils": "1.2.3",
"mkdirp": "0.5.1",
"next-server": "8.1.1-canary.55",
"node-libs-browser": "2.2.0",
"prop-types": "15.7.2",
"prop-types-exact": "1.2.0",
"react-error-overlay": "5.1.6",
Expand All @@ -96,6 +96,9 @@
"unfetch": "4.1.0",
"url": "0.11.0",
"watchpack": "2.0.0-beta.4",
"webpack": "4.32.2",
"webpack-dev-middleware": "3.7.0",
"webpack-hot-middleware": "2.25.0",
"webpack-sources": "1.3.0",
"worker-farm": "1.7.0"
},
Expand Down Expand Up @@ -126,19 +129,15 @@
"@types/styled-jsx": "2.2.8",
"@types/text-table": "0.2.1",
"@types/webpack-sources": "0.1.5",
"@zeit/ncc": "0.20.1",
"@zeit/ncc": "0.18.5",
"arg": "4.1.0",
"autodll-webpack-plugin": "0.4.2",
"babel-plugin-dynamic-import-node": "2.2.0",
"nanoid": "2.0.3",
"resolve": "1.11.0",
"taskr": "1.1.0",
"text-table": "0.2.0",
"typescript": "3.5.1",
"unistore": "3.4.1",
"webpack": "4.32.2",
"webpack-dev-middleware": "3.7.0",
"webpack-hot-middleware": "2.25.0"
"unistore": "3.4.1"
},
"engines": {
"node": ">= 8.0.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/next/server/hot-reloader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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.js'
import webpack from 'webpack'
import getBaseWebpackConfig from '../build/webpack-config'
import {
IS_BUNDLED_PAGE_REGEX,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/on-demand-entry-handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DynamicEntryPlugin from 'next/dist/compiled/webpack-DynamicEntryPlugin'
import DynamicEntryPlugin from 'webpack/lib/DynamicEntryPlugin'
import { EventEmitter } from 'events'
import { join, posix } from 'path'
import { parse } from 'url'
Expand Down
12 changes: 8 additions & 4 deletions packages/next/taskfile-ncc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { basename, dirname, extname, join, relative } = require('path')
module.exports = function (task) {
task.plugin('ncc', {}, function * (file, options) {
return ncc(join(__dirname, file.dir, file.base), {
filename: file.base,
// cannot bundle
externals: ['chokidar'],
...options
}).then(({ code, assets }) => {
Object.keys(assets).forEach(key =>
Expand All @@ -19,7 +20,7 @@ module.exports = function (task) {
)

if (options && options.packageName) {
writePackageManifest.call(this, options.packageName, file.base)
writePackageManifest.call(this, options.packageName)
}

file.data = Buffer.from(code, 'utf8')
Expand All @@ -30,9 +31,12 @@ module.exports = function (task) {
// This function writes a minimal `package.json` file for a compiled package.
// It defines `name`, `main`, `author`, and `license`. It also defines `types`.
// n.b. types intended for development usage only.
function writePackageManifest (packageName, main) {
function writePackageManifest (packageName) {
const packagePath = require.resolve(packageName + '/package.json')
let { name, author, license, types, typings } = require(packagePath)
let { name, main, author, license, types, typings } = require(packagePath)
if (!main) {
main = 'index.js'
}

let typesFile = types || typings
if (typesFile) {
Expand Down

0 comments on commit 31b3106

Please sign in to comment.