1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Move plugins and loaders to webpack folder (#4618)

Also adds basic `flow` to webpack.js and the plugins.
This commit is contained in:
Tim Neutkens 2018-06-16 19:23:02 +02:00 committed by GitHub
parent 82f2e08eab
commit d674dcc426
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 2084 additions and 16 deletions

View file

@ -1,3 +1,5 @@
// @flow
import type {NextConfig} from '../server/config'
import path, {sep} from 'path'
import webpack from 'webpack'
import resolve from 'resolve'
@ -6,12 +8,12 @@ import CaseSensitivePathPlugin from 'case-sensitive-paths-webpack-plugin'
import WriteFilePlugin from 'write-file-webpack-plugin'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import {getPages} from './webpack/utils'
import PagesPlugin from './plugins/pages-plugin'
import NextJsSsrImportPlugin from './plugins/nextjs-ssr-import'
import DynamicChunksPlugin from './plugins/dynamic-chunks-plugin'
import UnlinkFilePlugin from './plugins/unlink-file-plugin'
import PagesManifestPlugin from './plugins/pages-manifest-plugin'
import BuildManifestPlugin from './plugins/build-manifest-plugin'
import PagesPlugin from './webpack/plugins/pages-plugin'
import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import'
import DynamicChunksPlugin from './webpack/plugins/dynamic-chunks-plugin'
import UnlinkFilePlugin from './webpack/plugins/unlink-file-plugin'
import PagesManifestPlugin from './webpack/plugins/pages-manifest-plugin'
import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR} from '../lib/constants'
function externalsConfig (dir, isServer) {
@ -48,7 +50,14 @@ function externalsConfig (dir, isServer) {
return externals
}
export default async function getBaseWebpackConfig (dir, {dev = false, isServer = false, buildId, config}) {
type BaseConfigContext = {|
dev: boolean,
isServer: boolean,
buildId: string,
config: NextConfig
|}
export default async function getBaseWebpackConfig (dir: string, {dev = false, isServer = false, buildId, config}: BaseConfigContext) {
const defaultLoaders = {
babel: {
loader: 'next-babel-loader',
@ -121,7 +130,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
modules: [
NEXT_PROJECT_ROOT_NODE_MODULES,
'node_modules',
path.join(__dirname, 'loaders'),
path.join(__dirname, 'webpack', 'loaders'), // The loaders Next.js provides
...nodePathList // Support for NODE_PATH environment variable
]
},

View file

@ -1,7 +1,7 @@
import babelLoader from 'babel-loader'
module.exports = babelLoader.custom(babel => {
const presetItem = babel.createConfigItem(require('../babel/preset'), {type: 'preset'})
const presetItem = babel.createConfigItem(require('../../babel/preset'), {type: 'preset'})
const reactJsxSourceItem = babel.createConfigItem(require('@babel/plugin-transform-react-jsx-source'), {type: 'plugin'})
const configs = new Set()

View file

@ -1,6 +1,6 @@
// @flow
import { RawSource } from 'webpack-sources'
import {BUILD_MANIFEST} from '../../lib/constants'
import {BUILD_MANIFEST} from '../../../lib/constants'
// This plugin creates a build-manifest.json for all assets that are being output
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production

View file

@ -1,6 +1,6 @@
// @flow
import { RawSource } from 'webpack-sources'
import {PAGES_MANIFEST, ROUTE_NAME_REGEX} from '../../lib/constants'
import {PAGES_MANIFEST, ROUTE_NAME_REGEX} from '../../../lib/constants'
// This plugin creates a pages-manifest.json from page entrypoints.
// This is used for mapping paths like `/` to `.next/dist/bundles/pages/index.js` when doing SSR

View file

@ -1,8 +1,9 @@
// @flow
import { ConcatSource } from 'webpack-sources'
import {
IS_BUNDLED_PAGE_REGEX,
ROUTE_NAME_REGEX
} from '../../lib/constants'
} from '../../../lib/constants'
class PageChunkTemplatePlugin {
apply (chunkTemplate) {
@ -42,7 +43,7 @@ class PageChunkTemplatePlugin {
}
export default class PagesPlugin {
apply (compiler) {
apply (compiler: any) {
compiler.plugin('compilation', (compilation) => {
compilation.chunkTemplate.apply(new PageChunkTemplatePlugin())
})

View file

@ -1,16 +1,18 @@
// @flow
import { join } from 'path'
import promisify from '../../lib/promisify'
import promisify from '../../../lib/promisify'
import fs from 'fs'
import { IS_BUNDLED_PAGE_REGEX } from '../../lib/constants'
import { IS_BUNDLED_PAGE_REGEX } from '../../../lib/constants'
const unlink = promisify(fs.unlink)
export default class UnlinkFilePlugin {
prevAssets: any
constructor () {
this.prevAssets = {}
}
apply (compiler) {
apply (compiler: any) {
compiler.plugin('after-emit', (compilation, callback) => {
const removed = Object.keys(this.prevAssets)
.filter((a) => IS_BUNDLED_PAGE_REGEX.test(a) && !compilation.assets[a])

View file

@ -0,0 +1,67 @@
// flow-typed signature: e7e7f59f1cdd9c963584b4620763fec3
// flow-typed version: <<STUB>>/uglifyjs-webpack-plugin_v1.1.6/flow_v0.73.0
/**
* This is an autogenerated libdef stub for:
*
* 'uglifyjs-webpack-plugin'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
declare module 'uglifyjs-webpack-plugin' {
declare module.exports: any;
}
/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'uglifyjs-webpack-plugin/dist/cjs' {
declare module.exports: any;
}
declare module 'uglifyjs-webpack-plugin/dist/index' {
declare module.exports: any;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/index' {
declare module.exports: any;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/minify' {
declare module.exports: any;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/versions' {
declare module.exports: any;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/worker' {
declare module.exports: any;
}
// Filename aliases
declare module 'uglifyjs-webpack-plugin/dist/cjs.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/cjs'>;
}
declare module 'uglifyjs-webpack-plugin/dist/index.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/index'>;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/index.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/uglify/index'>;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/minify.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/uglify/minify'>;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/versions.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/uglify/versions'>;
}
declare module 'uglifyjs-webpack-plugin/dist/uglify/worker.js' {
declare module.exports: $Exports<'uglifyjs-webpack-plugin/dist/uglify/worker'>;
}

1957
flow-typed/npm/webpack_vx.x.x.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,32 @@
// flow-typed signature: 4a61661df41490b27db4f4aa0c03929e
// flow-typed version: <<STUB>>/write-file-webpack-plugin_v4.2.0/flow_v0.73.0
/**
* This is an autogenerated libdef stub for:
*
* 'write-file-webpack-plugin'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
declare module 'write-file-webpack-plugin' {
declare module.exports: any;
}
/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'write-file-webpack-plugin/dist/index' {
declare module.exports: any;
}
// Filename aliases
declare module 'write-file-webpack-plugin/dist/index.js' {
declare module.exports: $Exports<'write-file-webpack-plugin/dist/index'>;
}