forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
52 lines (48 loc) · 1.21 KB
/
bundle.js
File metadata and controls
52 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { resolve, dirname, basename } from 'path'
import webpack from 'webpack'
export default function bundle (src, dst) {
const compiler = webpack({
entry: src,
output: {
path: dirname(dst),
filename: basename(dst),
libraryTarget: 'commonjs2'
},
externals: [
'react',
'react-dom',
{
[require.resolve('react')]: 'react',
[require.resolve('../../lib/link')]: 'next/link',
[require.resolve('../../lib/css')]: 'next/css'
}
],
resolveLoader: {
root: resolve(__dirname, '..', '..', 'node_modules')
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
sourceMap: false
})
],
module: {
preLoaders: [
{ test: /\.json$/, loader: 'json-loader' }
]
}
})
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) return reject(err)
const jsonStats = stats.toJson()
if (jsonStats.errors.length > 0) {
const error = new Error(jsonStats.errors[0])
error.errors = jsonStats.errors
error.warnings = jsonStats.warnings
return reject(error)
}
resolve()
})
})
}