2020-04-06 11:17:22 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const resolve = require('@rollup/plugin-node-resolve')
|
|
|
|
const replace = require('@rollup/plugin-replace')
|
|
|
|
const { terser } = require('rollup-plugin-terser')
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const pkgJson = require('../package.json')
|
|
|
|
|
|
|
|
const rootDir = path.join(__dirname, '..')
|
|
|
|
const srcDir = path.join(rootDir, pkgJson.directories.src)
|
|
|
|
const dstDir = path.join(rootDir, pkgJson.directories.lib)
|
|
|
|
|
|
|
|
function camelise (str) {
|
|
|
|
return str.replace(/-([a-z])/g,
|
|
|
|
function (m, w) {
|
|
|
|
return w.toUpperCase()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const pkgName = pkgJson.name
|
|
|
|
const pkgCamelisedName = camelise(pkgName)
|
|
|
|
|
|
|
|
const input = path.join(srcDir, 'js', 'index.js')
|
|
|
|
|
|
|
|
module.exports = [
|
2020-04-20 22:50:53 +00:00
|
|
|
{ // Native JS
|
2020-04-06 11:17:22 +00:00
|
|
|
input: input,
|
|
|
|
output: [
|
|
|
|
{
|
2020-04-07 17:29:23 +00:00
|
|
|
file: path.join(rootDir, pkgJson.browser),
|
2020-04-07 22:21:02 +00:00
|
|
|
format: 'es'
|
2020-04-20 22:50:53 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
replace({
|
|
|
|
'process.browser': true
|
|
|
|
})
|
|
|
|
],
|
|
|
|
external: ['bigint-mod-arith']
|
|
|
|
},
|
|
|
|
{ // Browser bundles
|
|
|
|
input: input,
|
|
|
|
output: [
|
2020-04-07 17:29:23 +00:00
|
|
|
{
|
2020-04-07 22:21:02 +00:00
|
|
|
file: path.join(dstDir, 'index.browser.bundle.iife.js'),
|
|
|
|
format: 'iife',
|
|
|
|
name: pkgCamelisedName
|
2020-04-06 11:17:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
file: path.join(dstDir, 'index.browser.bundle.mod.js'),
|
|
|
|
format: 'es'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
replace({
|
|
|
|
'process.browser': true
|
|
|
|
}),
|
|
|
|
resolve({
|
|
|
|
browser: true
|
2020-04-07 22:21:02 +00:00
|
|
|
}),
|
2020-04-20 22:50:53 +00:00
|
|
|
terser()
|
2020-04-06 11:17:22 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{ // Node
|
|
|
|
input: input,
|
|
|
|
output: {
|
2020-04-08 09:37:02 +00:00
|
|
|
file: path.join(rootDir, pkgJson.main),
|
2020-04-20 22:50:53 +00:00
|
|
|
format: 'cjs',
|
|
|
|
esModule: false,
|
|
|
|
externalLiveBindings: false
|
2020-04-07 15:03:30 +00:00
|
|
|
},
|
2020-04-07 22:21:02 +00:00
|
|
|
plugins: [
|
|
|
|
replace({
|
|
|
|
'process.browser': false
|
|
|
|
})
|
2020-04-20 22:50:53 +00:00
|
|
|
],
|
|
|
|
external: ['bigint-mod-arith']
|
2020-04-06 11:17:22 +00:00
|
|
|
}
|
|
|
|
]
|