-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Universal Webpack #3578
Universal Webpack #3578
Changes from 65 commits
fcb3430
c1ebbf6
83916b7
443ece9
0aacb17
ad6cc8a
6ce025e
c3914ea
b1aac7b
7bee9a7
5373354
dc3f242
6fabf34
654c48e
3192950
25e8bca
82e5505
c8ff14b
b4fbe50
a057415
8226bd9
91569e0
e5d2078
b843e6e
9da6404
5cb819a
b97bc2f
89f9793
aec6aa1
888bc35
ab26369
8859c5f
84d785a
c5ccf23
bb5cf9a
565bf54
122fc92
c487416
c6c7e15
008e659
fa4b18f
2057482
7bd3178
c136af8
bf78292
5e5b9e8
7b339a4
6494359
f8f1fba
820d3c3
48e4d63
190b930
573d4a6
e0d2a41
7d83ae4
9eac841
ea67454
340b93d
52605da
3347940
5434104
d4b1d9b
4ca1a44
5821d49
91ad193
dbbdec4
5fd08f1
fcea07c
04651be
1f023a8
435b60d
1a2ab91
495e0a4
2a3aa74
8e96607
6473226
30af0bf
d82c566
94fdee5
bd27a7e
deff65a
ef06a04
de8d0fb
c80228b
49e2808
7106aff
a10c21e
fb7c862
d948ef5
763a1d2
9b709c5
6b62551
4617987
6833e8b
516fa62
97f45e9
e57c236
7ed60b7
4911d0a
f820315
8e9f8c7
7e9fa41
1e6e829
3897e64
9f4de5b
0aa6aac
65c0747
a13f3e4
15d2280
280b9c7
3479800
49b119b
5650e50
e7a938c
827c813
aeea881
f9e9712
6845af9
89f5563
c8f9c70
53c9a6b
d6dee1e
ef5f3de
96b99ac
440b39f
c73853c
3269104
e38c605
01c84a1
91ce3f9
a62b764
415de61
3de72fc
256ad20
563c9c3
3b0d1f8
3018694
1226b3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,6 @@ export default class App extends Component { | |
} | ||
} | ||
|
||
componentDidCatch (error, info) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timneutkens for SSR we don't need this. We can easily catch them with try catch. This is for development to track errors inside render functions. Earlier, we had to hack React to get this. Please do not remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timneutkens This is the hack we had.
|
||
error.stack = `${error.stack}\n\n${info.componentStack}` | ||
window.next.renderError(error) | ||
this.setState({ hasError: true }) | ||
} | ||
|
||
render () { | ||
if (this.state.hasError) return null | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,17 @@ import { tmpdir } from 'os' | |
import { join } from 'path' | ||
import fs from 'mz/fs' | ||
import uuid from 'uuid' | ||
import del from 'del' | ||
import webpack from './webpack' | ||
import replaceCurrentBuild from './replace' | ||
// import del from 'del' | ||
import webpack from 'webpack' | ||
import getConfig from '../config' | ||
import baseConfig from './webpack/base.config.js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename like: |
||
// import replaceCurrentBuild from './replace' | ||
import md5File from 'md5-file/promise' | ||
|
||
export default async function build (dir, conf = null) { | ||
const config = getConfig(dir, conf) | ||
const buildId = uuid.v4() | ||
const tempDir = tmpdir() | ||
const buildDir = join(tempDir, uuid.v4()) | ||
|
||
try { | ||
await fs.access(tempDir, fs.constants.W_OK) | ||
|
@@ -19,26 +21,34 @@ export default async function build (dir, conf = null) { | |
throw err | ||
} | ||
|
||
const compiler = await webpack(dir, { buildId, buildDir, conf }) | ||
|
||
try { | ||
const stats = await runCompiler(compiler) | ||
await writeBuildStats(buildDir, stats) | ||
await writeBuildId(buildDir, buildId) | ||
const configs = await Promise.all([ | ||
baseConfig(dir, { buildId, isServer: false, config }), | ||
baseConfig(dir, { buildId, isServer: true, config }) | ||
]) | ||
|
||
await runCompiler(configs) | ||
|
||
// await fs.writeFile(join(dir, '.next', 'server-stats.json'), JSON.stringify(serverStats), 'utf8') | ||
// await fs.writeFile(join(dir, '.next', 'client-stats.json'), JSON.stringify(stats), 'utf8') | ||
|
||
await writeBuildStats(dir) | ||
await writeBuildId(dir, buildId) | ||
} catch (err) { | ||
console.error(`> Failed to build on ${buildDir}`) | ||
console.error(`> Failed to build`) | ||
throw err | ||
} | ||
|
||
await replaceCurrentBuild(dir, buildDir) | ||
// await replaceCurrentBuild(dir, buildDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure we documented why we removed it. |
||
|
||
// no need to wait | ||
del(buildDir, { force: true }) | ||
// del(buildDir, { force: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to delete the current directory before running next build. |
||
} | ||
|
||
function runCompiler (compiler) { | ||
return new Promise((resolve, reject) => { | ||
compiler.run((err, stats) => { | ||
return new Promise(async (resolve, reject) => { | ||
const webpackCompiler = await webpack(await compiler) | ||
webpackCompiler.run((err, stats) => { | ||
if (err) return reject(err) | ||
|
||
const jsonStats = stats.toJson() | ||
|
@@ -55,7 +65,7 @@ function runCompiler (compiler) { | |
}) | ||
} | ||
|
||
async function writeBuildStats (dir, stats) { | ||
async function writeBuildStats (dir) { | ||
// Here we can't use hashes in webpack chunks. | ||
// That's because the "app.js" is not tied to a chunk. | ||
// It's created by merging a few assets. (commons.js and main.js) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ module.exports = function (content, sourceMap) { | |
this.callback(null, `${content} | ||
(function (Component, route) { | ||
if (!module.hot) return | ||
if (!__resourceQuery) return | ||
// if (!__resourceQuery) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get rid these. (Remove commented lines). |
||
|
||
var qs = require('querystring') | ||
var params = qs.parse(__resourceQuery.slice(1)) | ||
if (params.entry == null) return | ||
// var qs = require('querystring') | ||
// var params = qs.parse(__resourceQuery.slice(1)) | ||
// if (params.entry == null) return | ||
|
||
console.log('ACCEPTING') | ||
module.hot.accept() | ||
Component.__route = route | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check this? This came with
16.0.0
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arunoda to support
preact
and the likes that haven't addedhydrate
yet 🕵️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ha. Shall we add a comment here about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea 👍