forked from nuxt/nuxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
83 lines (79 loc) · 2.2 KB
/
rollup.config.js
File metadata and controls
83 lines (79 loc) · 2.2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import path from 'path'
import { readJSONSync } from 'fs-extra'
import jsonPlugin from '@rollup/plugin-json'
import commonjsPlugin from '@rollup/plugin-commonjs'
import replacePlugin from '@rollup/plugin-replace'
import aliasPlugin from '@rollup/plugin-alias'
import nodeResolvePlugin from '@rollup/plugin-node-resolve'
import licensePlugin from 'rollup-plugin-license'
import defaultsDeep from 'lodash/defaultsDeep'
import consola from 'consola'
import { builtins } from './builtins'
export default function rollupConfig ({
rootDir = process.cwd(),
plugins = [],
input = 'src/index.js',
replace = {},
alias = {},
externals = [],
resolve = {
only: [
/lodash/
]
},
...options
}, pkg) {
if (!pkg) {
pkg = readJSONSync(path.resolve(rootDir, 'package.json'))
}
const name = path.basename(pkg.name.replace('-edge', ''))
return defaultsDeep({}, options, {
input: path.resolve(rootDir, input),
output: {
dir: path.resolve(rootDir, 'dist'),
entryFileNames: `${name}.js`,
chunkFileNames: `${name}-[name].js`,
format: 'cjs',
preferConst: true
},
external: [
// Dependencies that will be installed alongise with the nuxt package
...Object.keys(pkg.dependencies || {}),
// Builtin node modules
...builtins,
// Explicit externals
...externals
],
plugins: [
aliasPlugin(alias),
replacePlugin({
exclude: 'node_modules/**',
delimiters: ['', ''],
values: {
__NODE_ENV__: process.env.NODE_ENV,
...replace
}
}),
nodeResolvePlugin(resolve),
commonjsPlugin(),
jsonPlugin(),
licensePlugin({
banner: [
'/*!',
` * ${pkg.name} v${pkg.version} (c) 2016-${new Date().getFullYear()}`,
`${(pkg.contributors || []).map(c => ` * - ${c.name}`).join('\n')}`,
' * - All the amazing contributors',
' * Released under the MIT License.',
' * Website: https://nuxtjs.org',
'*/'
].join('\n')
})
].concat(plugins),
onwarn (warning, warn) {
if (warning.plugin === 'rollup-plugin-license') {
return
}
consola.warn(warning)
}
})
}