mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Source map support (#279)
* generate source-maps on development * remove unused dep
This commit is contained in:
parent
6ad1e23167
commit
12f31b5bf3
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
import 'source-map-support/register'
|
||||||
import { resolve, join } from 'path'
|
import { resolve, join } from 'path'
|
||||||
import parseArgs from 'minimist'
|
import parseArgs from 'minimist'
|
||||||
import { exists } from 'mz/fs'
|
import { exists } from 'mz/fs'
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
"react-hot-loader": "3.0.0-beta.6",
|
"react-hot-loader": "3.0.0-beta.6",
|
||||||
"read-pkg-up": "2.0.0",
|
"read-pkg-up": "2.0.0",
|
||||||
"send": "0.14.1",
|
"send": "0.14.1",
|
||||||
|
"source-map-support": "0.4.6",
|
||||||
"strip-ansi": "3.0.1",
|
"strip-ansi": "3.0.1",
|
||||||
"url": "0.11.0",
|
"url": "0.11.0",
|
||||||
"webpack": "1.13.3",
|
"webpack": "1.13.3",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import loaderUtils from 'loader-utils'
|
import loaderUtils from 'loader-utils'
|
||||||
|
|
||||||
module.exports = function (content) {
|
module.exports = function (content, sourceMap) {
|
||||||
this.cacheable()
|
this.cacheable()
|
||||||
|
|
||||||
const query = loaderUtils.parseQuery(this.query)
|
const query = loaderUtils.parseQuery(this.query)
|
||||||
|
@ -10,7 +10,7 @@ module.exports = function (content) {
|
||||||
const opts = { context, content, regExp }
|
const opts = { context, content, regExp }
|
||||||
const interpolatedName = loaderUtils.interpolateName(this, name, opts)
|
const interpolatedName = loaderUtils.interpolateName(this, name, opts)
|
||||||
|
|
||||||
this.emitFile(interpolatedName, content)
|
this.emitFile(interpolatedName, content, sourceMap)
|
||||||
|
|
||||||
return content
|
this.callback(null, content, sourceMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { resolve, relative } from 'path'
|
import { resolve, relative } from 'path'
|
||||||
|
|
||||||
module.exports = function (content) {
|
module.exports = function (content, sourceMap) {
|
||||||
this.cacheable()
|
this.cacheable()
|
||||||
|
|
||||||
const route = getRoute(this)
|
const route = getRoute(this)
|
||||||
|
|
||||||
return `${content}
|
this.callback(null, `${content}
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
module.hot.accept()
|
module.hot.accept()
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ module.exports = function (content) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`, sourceMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextPagesDir = resolve(__dirname, '..', '..', '..', 'pages')
|
const nextPagesDir = resolve(__dirname, '..', '..', '..', 'pages')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { resolve, join } from 'path'
|
import { resolve, join } from 'path'
|
||||||
|
import { createHash } from 'crypto'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import glob from 'glob-promise'
|
import glob from 'glob-promise'
|
||||||
import WriteFilePlugin from 'write-file-webpack-plugin'
|
import WriteFilePlugin from 'write-file-webpack-plugin'
|
||||||
|
@ -101,6 +102,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
|
||||||
loader: 'babel',
|
loader: 'babel',
|
||||||
include: nextPagesDir,
|
include: nextPagesDir,
|
||||||
query: {
|
query: {
|
||||||
|
sourceMaps: dev ? 'both' : false,
|
||||||
plugins: [
|
plugins: [
|
||||||
[
|
[
|
||||||
require.resolve('babel-plugin-module-resolver'),
|
require.resolve('babel-plugin-module-resolver'),
|
||||||
|
@ -120,6 +122,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
|
||||||
return /node_modules/.test(str) && str.indexOf(nextPagesDir) !== 0 && str.indexOf(dir) !== 0
|
return /node_modules/.test(str) && str.indexOf(nextPagesDir) !== 0 && str.indexOf(dir) !== 0
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
|
sourceMaps: dev ? 'both' : false,
|
||||||
presets: ['es2015', 'react'],
|
presets: ['es2015', 'react'],
|
||||||
plugins: [
|
plugins: [
|
||||||
require.resolve('babel-plugin-react-require'),
|
require.resolve('babel-plugin-react-require'),
|
||||||
|
@ -155,7 +158,15 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
|
||||||
path: join(dir, '.next'),
|
path: join(dir, '.next'),
|
||||||
filename: '[name]',
|
filename: '[name]',
|
||||||
libraryTarget: 'commonjs2',
|
libraryTarget: 'commonjs2',
|
||||||
publicPath: hotReload ? '/_webpack/' : null
|
publicPath: hotReload ? '/_webpack/' : null,
|
||||||
|
devtoolModuleFilenameTemplate ({ resourcePath }) {
|
||||||
|
const hash = createHash('sha1')
|
||||||
|
hash.update(Date.now() + '')
|
||||||
|
const id = hash.digest('hex').slice(0, 7)
|
||||||
|
|
||||||
|
// append hash id for cache busting
|
||||||
|
return `webpack:///${resourcePath}?${id}`
|
||||||
|
}
|
||||||
},
|
},
|
||||||
externals: [
|
externals: [
|
||||||
'react',
|
'react',
|
||||||
|
@ -186,6 +197,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
|
||||||
module: {
|
module: {
|
||||||
loaders
|
loaders
|
||||||
},
|
},
|
||||||
|
devtool: dev ? 'inline-source-map' : false,
|
||||||
customInterpolateName: function (url, name, opts) {
|
customInterpolateName: function (url, name, opts) {
|
||||||
return interpolateNames.get(this.resourcePath) || url
|
return interpolateNames.get(this.resourcePath) || url
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue