2018-10-17 21:28:25 +00:00
|
|
|
import path from 'path'
|
|
|
|
import { readJSONSync } from 'fs-extra'
|
2020-01-24 07:37:34 +00:00
|
|
|
import jsonPlugin from '@rollup/plugin-json'
|
|
|
|
import commonjsPlugin from '@rollup/plugin-commonjs'
|
|
|
|
import replacePlugin from '@rollup/plugin-replace'
|
|
|
|
import aliasPlugin from '@rollup/plugin-alias'
|
2020-12-22 17:07:50 +00:00
|
|
|
// import nodeResolvePlugin from '@rollup/plugin-node-resolve'
|
2018-10-17 21:28:25 +00:00
|
|
|
import licensePlugin from 'rollup-plugin-license'
|
2021-05-24 17:34:23 +00:00
|
|
|
import esbuild from 'rollup-plugin-esbuild'
|
2020-12-22 17:07:50 +00:00
|
|
|
import { defaultsDeep } from 'lodash'
|
2018-10-17 21:28:25 +00:00
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export default function rollupConfig ({
|
2018-10-17 21:28:25 +00:00
|
|
|
rootDir = process.cwd(),
|
|
|
|
plugins = [],
|
|
|
|
input = 'src/index.js',
|
|
|
|
replace = {},
|
|
|
|
alias = {},
|
2020-02-06 13:02:05 +00:00
|
|
|
externals = [],
|
2018-10-17 21:28:25 +00:00
|
|
|
...options
|
|
|
|
}, pkg) {
|
|
|
|
if (!pkg) {
|
|
|
|
pkg = readJSONSync(path.resolve(rootDir, 'package.json'))
|
|
|
|
}
|
|
|
|
|
2018-12-29 20:51:47 +00:00
|
|
|
const name = path.basename(pkg.name.replace('-edge', ''))
|
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
return defaultsDeep({}, options, {
|
|
|
|
input: path.resolve(rootDir, input),
|
|
|
|
output: {
|
2018-10-30 20:42:53 +00:00
|
|
|
dir: path.resolve(rootDir, 'dist'),
|
2018-12-29 20:51:47 +00:00
|
|
|
entryFileNames: `${name}.js`,
|
|
|
|
chunkFileNames: `${name}-[name].js`,
|
2018-12-29 20:31:28 +00:00
|
|
|
format: 'cjs',
|
2023-02-02 00:02:57 +00:00
|
|
|
generatedCode: {
|
|
|
|
constBindings: true
|
|
|
|
}
|
2018-10-17 21:28:25 +00:00
|
|
|
},
|
2020-12-22 17:07:50 +00:00
|
|
|
external: externals,
|
2018-10-17 21:28:25 +00:00
|
|
|
plugins: [
|
|
|
|
aliasPlugin(alias),
|
|
|
|
replacePlugin({
|
|
|
|
exclude: 'node_modules/**',
|
|
|
|
delimiters: ['', ''],
|
2021-02-23 09:29:00 +00:00
|
|
|
preventAssignment: true,
|
2018-10-17 21:28:25 +00:00
|
|
|
values: {
|
|
|
|
__NODE_ENV__: process.env.NODE_ENV,
|
|
|
|
...replace
|
|
|
|
}
|
|
|
|
}),
|
2020-12-22 17:07:50 +00:00
|
|
|
// nodeResolvePlugin({
|
|
|
|
// preferBuiltins: true,
|
|
|
|
// resolveOnly: [
|
|
|
|
// /lodash/
|
|
|
|
// ]
|
|
|
|
// }),
|
2021-05-24 17:34:23 +00:00
|
|
|
esbuild({ target: 'es2019' }),
|
2020-05-16 13:07:56 +00:00
|
|
|
commonjsPlugin({ include: /node_modules/ }),
|
2018-10-17 21:28:25 +00:00
|
|
|
jsonPlugin(),
|
|
|
|
licensePlugin({
|
|
|
|
banner: [
|
2019-11-26 22:42:39 +00:00
|
|
|
'/*!',
|
2018-10-17 21:28:25 +00:00
|
|
|
` * ${pkg.name} v${pkg.version} (c) 2016-${new Date().getFullYear()}`,
|
2021-02-10 14:06:04 +00:00
|
|
|
' * Released under the MIT License',
|
|
|
|
' * Repository: https://github.com/nuxt/nuxt.js',
|
2019-11-26 22:42:39 +00:00
|
|
|
' * Website: https://nuxtjs.org',
|
|
|
|
'*/'
|
2018-10-17 21:28:25 +00:00
|
|
|
].join('\n')
|
|
|
|
})
|
2020-05-16 13:07:56 +00:00
|
|
|
].concat(plugins)
|
2018-10-17 21:28:25 +00:00
|
|
|
})
|
|
|
|
}
|