mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make sure dynamic imports works on Windows (#3641)
* Make sure dynamic imports works on Windows * Fix an issue with the load test firmware. * Fix symlink creation on Unix
This commit is contained in:
parent
5818e6f781
commit
4b143fc232
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,6 +5,7 @@ dist
|
|||
# dependencies
|
||||
node_modules
|
||||
package-lock.json
|
||||
test/node_modules
|
||||
|
||||
# logs
|
||||
*.log
|
||||
|
|
|
@ -126,12 +126,14 @@
|
|||
"husky": "0.14.3",
|
||||
"jest-cli": "21.2.0",
|
||||
"lint-staged": "4.2.3",
|
||||
"mkdirp": "0.5.1",
|
||||
"node-fetch": "1.7.3",
|
||||
"node-notifier": "5.1.2",
|
||||
"nyc": "11.2.1",
|
||||
"portfinder": "1.0.13",
|
||||
"react": "16.2.0",
|
||||
"react-dom": "16.2.0",
|
||||
"rimraf": "2.6.2",
|
||||
"standard": "9.0.2",
|
||||
"taskr": "1.1.0",
|
||||
"wd": "1.4.1"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { join, sep } from 'path'
|
||||
import { join } from 'path'
|
||||
|
||||
// This plugin modifies the require-ensure code generated by Webpack
|
||||
// to work with Next.js SSR
|
||||
|
@ -13,7 +13,10 @@ export default class NextJsSsrImportPlugin {
|
|||
compilation.mainTemplate.plugin('require-ensure', (code) => {
|
||||
// Update to load chunks from our custom chunks directory
|
||||
const chunksDirPath = join(this.dir, this.dist, 'dist')
|
||||
let updatedCode = code.replace('require("./"', `require("${chunksDirPath}${sep}"`)
|
||||
// Make sure even in windows, the path looks like in unix
|
||||
// Node.js require system will convert it accordingly
|
||||
const chunksDirPathNormalized = chunksDirPath.replace(/\\/g, '/')
|
||||
let updatedCode = code.replace('require("./"', `require("${chunksDirPathNormalized}/"`)
|
||||
|
||||
// Replace a promise equivalent which runs in the same loop
|
||||
// If we didn't do this webpack's module loading process block us from
|
||||
|
|
15
taskfile.js
15
taskfile.js
|
@ -1,5 +1,7 @@
|
|||
const notifier = require('node-notifier')
|
||||
const childProcess = require('child_process')
|
||||
const rimraf = require('rimraf')
|
||||
const mkdirp = require('mkdirp')
|
||||
const isWindows = /^win/.test(process.platform)
|
||||
|
||||
export async function compile (task) {
|
||||
|
@ -26,12 +28,21 @@ export async function client (task, opts) {
|
|||
notify('Compiled client files')
|
||||
}
|
||||
|
||||
// Create node_modules/next for the use of test apps
|
||||
export async function symlinkNextForTesting () {
|
||||
rimraf.sync('test/node_modules/next')
|
||||
mkdirp.sync('test/node_modules')
|
||||
|
||||
const symlinkCommand = isWindows ? 'mklink /D "next" "..\\..\\"' : 'ln -s ../../ next'
|
||||
childProcess.execSync(symlinkCommand, { cwd: 'test/node_modules' })
|
||||
}
|
||||
|
||||
export async function copy (task) {
|
||||
await task.source('pages/**/*.js').target('dist/pages')
|
||||
}
|
||||
|
||||
export async function build (task) {
|
||||
await task.serial(['copy', 'compile'])
|
||||
await task.serial(['symlinkNextForTesting', 'copy', 'compile'])
|
||||
}
|
||||
|
||||
export default async function (task) {
|
||||
|
@ -53,8 +64,10 @@ export async function release (task) {
|
|||
// the lifetime of the original npm script.
|
||||
|
||||
export async function pretest (task) {
|
||||
// Start chromedriver
|
||||
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
|
||||
childProcess.spawn(processName, { stdio: 'inherit' })
|
||||
|
||||
// We need to do this, otherwise this task's process will keep waiting.
|
||||
setTimeout(() => process.exit(0), 2000)
|
||||
}
|
||||
|
|
1
test/node_modules/next
generated
vendored
1
test/node_modules/next
generated
vendored
|
@ -1 +0,0 @@
|
|||
../..
|
|
@ -4083,7 +4083,7 @@ mkdirp@0.5.0:
|
|||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
|
||||
mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
|
||||
dependencies:
|
||||
|
@ -5123,7 +5123,7 @@ right-align@^0.1.1:
|
|||
dependencies:
|
||||
align-text "^0.1.1"
|
||||
|
||||
rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
|
||||
rimraf@2, rimraf@2.6.2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue