Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const cache = require('gulp-cached')
const notify_ = require('gulp-notify')
const benchmark = require('gulp-benchmark')
const sequence = require('run-sequence')
const webpack = require('webpack-stream')
const webpack = require('webpack')
const webpackStream = require('webpack-stream')
const del = require('del')
const jest = require('gulp-jest')

Expand Down Expand Up @@ -88,37 +89,36 @@ gulp.task('build', [
gulp.task('build-prefetcher', ['compile-lib', 'compile-client'], () => {
return gulp
.src('client/next-prefetcher.js')
.pipe(webpack({
quiet: true,
.pipe(webpackStream({
output: { filename: 'next-prefetcher-bundle.js' },
plugins: [
new webpack.webpack.DefinePlugin({
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
],
module: {
loaders: [
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
'babelrc': false,
'presets': [
loader: 'babel-loader',
options: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we could decorate this with options.babel() to make it easier to config babel for next?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate options.babel() ?

babelrc: false,
presets: [
['env', {
'targets': {
targets: {
// All browsers which supports service workers
'browsers': ['chrome 49', 'firefox 49', 'opera 41']
browsers: ['chrome 49', 'firefox 49', 'opera 41']
}
}]
]
}
}
]
}
}))
}, webpack))
.pipe(gulp.dest('dist/client'))
.pipe(notify('Built release prefetcher'))
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"strip-ansi": "3.0.1",
"styled-jsx": "0.3.0",
"url": "0.11.0",
"webpack": "1.14.0",
"webpack": "2.2.0-rc.3",
"webpack-dev-middleware": "1.9.0",
"webpack-hot-middleware": "2.14.0",
"write-file-webpack-plugin": "3.4.2"
Expand Down
99 changes: 79 additions & 20 deletions server/build/plugins/watch-remove-event-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ export default class WatchRemoveEventPlugin {
apply (compiler) {
compiler.removedFiles = []

compiler.plugin('environment', () => {
if (!compiler.watchFileSystem) return

const { watchFileSystem } = compiler
const { watch } = watchFileSystem

watchFileSystem.watch = (files, dirs, missing, startTime, options, callback, callbackUndelayed) => {
const result = watch.call(watchFileSystem, files, dirs, missing, startTime, options, (...args) => {
compiler.removedFiles = this.removedFiles
this.removedFiles = []
callback(...args)
}, callbackUndelayed)

const watchpack = watchFileSystem.watcher
watchpack.fileWatchers.forEach((w) => {
w.on('remove', this.onRemove.bind(this, watchpack, w.path))
})
return result
}
})
if (!compiler.watchFileSystem) return

const { watchFileSystem } = compiler
const { watch } = watchFileSystem

watchFileSystem.watch = (files, dirs, missing, startTime, options, callback, callbackUndelayed) => {
const result = watch.call(watchFileSystem, files, dirs, missing, startTime, options, (...args) => {
compiler.removedFiles = this.removedFiles
this.removedFiles = []
callback(...args)
}, callbackUndelayed)

const watchpack = watchFileSystem.watcher
watchpack.fileWatchers.forEach((w) => {
w.on('remove', this.onRemove.bind(this, watchpack, w.path))
})
return result
}
}

onRemove (watchpack, file) {
Expand All @@ -38,3 +36,64 @@ export default class WatchRemoveEventPlugin {
watchpack._onChange(file)
}
}

// monkeypatching watchpack module to fix
// https://github.com/webpack/watchpack/pull/33

let DirectoryWatcher
try {
DirectoryWatcher = require('webpack/node_modules/watchpack/lib/DirectoryWatcher')
} catch (err) {
DirectoryWatcher = require('watchpack/lib/DirectoryWatcher')
}

/* eslint-disable */
var FS_ACCURENCY = 10000;

function withoutCase(str) {
return str.toLowerCase();
}

DirectoryWatcher.prototype.setFileTime = function setFileTime(filePath, mtime, initial, type) {
var now = Date.now();
var old = this.files[filePath];

this.files[filePath] = [initial ? Math.min(now, mtime) : now, mtime];

// we add the fs accurency to reach the maximum possible mtime
if(mtime)
mtime = mtime + FS_ACCURENCY;

if(!old) {
if(mtime) {
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
if(!initial || w.checkStartTime(mtime, initial)) {
w.emit("change", mtime);
}
});
}
}
} else if(!initial && mtime && type !== "add") {
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
w.emit("change", mtime);
});
}
} else if(!initial && !mtime) {
delete this.files[filePath];
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
w.emit("remove");
});
}
}
if(this.watchers[withoutCase(this.path)]) {
this.watchers[withoutCase(this.path)].forEach(function(w) {
if(!initial || w.checkStartTime(mtime, initial)) {
w.emit("change", filePath, mtime);
}
});
}
};
/* eslint-enable */
32 changes: 19 additions & 13 deletions server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export default async function createCompiler (dir, { dev = false, quiet = false
const minChunks = pages.filter((p) => p !== documentPage).length

const plugins = [
new webpack.LoaderOptionsPlugin({
options: {
context: dir,
customInterpolateName (url, name, opts) {
return interpolateNames.get(this.resourcePath) || url
}
}
}),
new WriteFilePlugin({
exitOnErrors: false,
log: false,
Expand All @@ -66,7 +74,6 @@ export default async function createCompiler (dir, { dev = false, quiet = false

if (dev) {
plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new DetachPlugin(),
Expand Down Expand Up @@ -104,7 +111,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false
mainBabelOptions.presets.push(require.resolve('./babel/preset'))
}

const loaders = (dev ? [{
const rules = (dev ? [{
test: /\.js(\?[^?]*)?$/,
loader: 'hot-self-accept-loader',
include: [
Expand All @@ -126,13 +133,13 @@ export default async function createCompiler (dir, { dev = false, quiet = false
exclude (str) {
return /node_modules/.test(str) && str.indexOf(nextPagesDir) !== 0
},
query: {
options: {
name: 'dist/[path][name].[ext]'
}
}, {
loader: 'babel',
loader: 'babel-loader',
include: nextPagesDir,
query: {
options: {
babelrc: false,
cacheDirectory: true,
sourceMaps: dev ? 'both' : false,
Expand All @@ -150,7 +157,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false
}
}, {
test: /\.js(\?[^?]*)?$/,
loader: 'babel',
loader: 'babel-loader',
include: [dir, nextPagesDir],
exclude (str) {
return /node_modules/.test(str) && str.indexOf(nextPagesDir) !== 0
Expand All @@ -165,7 +172,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false
path: join(dir, '.next'),
filename: '[name]',
libraryTarget: 'commonjs2',
publicPath: dev ? '/_webpack/' : null,
publicPath: '/_webpack/',
devtoolModuleFilenameTemplate ({ resourcePath }) {
const hash = createHash('sha1')
hash.update(Date.now() + '')
Expand All @@ -176,28 +183,27 @@ export default async function createCompiler (dir, { dev = false, quiet = false
}
},
resolve: {
root: [
modules: [
nodeModulesDir,
join(dir, 'node_modules')
].concat(
(process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
.filter((p) => !!p)
)
},
resolveLoader: {
root: [
modules: [
nodeModulesDir,
join(__dirname, 'loaders')
]
},
plugins,
module: {
loaders
rules
},
devtool: dev ? 'inline-source-map' : false,
customInterpolateName: function (url, name, opts) {
return interpolateNames.get(this.resourcePath) || url
}
performance: { hints: false }
}

if (config.webpack) {
Expand Down