2021-12-25 14:39:47 +01:00
|
|
|
const path = require('path')
|
|
|
|
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
|
|
const progress = require('rollup-plugin-progress')
|
|
|
|
const replace = require('@rollup/plugin-replace')
|
|
|
|
const globals = require('rollup-plugin-node-globals')
|
|
|
|
const commonjs = require('@rollup/plugin-commonjs')
|
|
|
|
const alias = require('@rollup/plugin-alias')
|
2022-11-29 15:20:28 +01:00
|
|
|
const terser = require('@rollup/plugin-terser');
|
2021-12-25 14:39:47 +01:00
|
|
|
const scss = require('rollup-plugin-scss')
|
2024-05-08 13:16:23 +02:00
|
|
|
const webWorkerLoader = require('@qortal/rollup-plugin-web-worker-loader')
|
2021-12-25 14:39:47 +01:00
|
|
|
const generateES5BuildConfig = require('./generateES5BuildConfig')
|
|
|
|
|
|
|
|
const generateInputs = (tree, inputs = {}) => {
|
2024-05-08 13:16:23 +02:00
|
|
|
for (const file of Object.values(tree)) {
|
|
|
|
inputs[file.file.split('.')[0]] = file.source
|
|
|
|
if (file.children) generateInputs(file.children, inputs)
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
return inputs
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const generateBuildConfig = ({ elementComponents, functionalComponents, otherOutputs, apiComponents, aliases, options, inlineComponents }) => {
|
2024-05-08 13:16:23 +02:00
|
|
|
const buildConfig = {
|
|
|
|
outputs: [
|
|
|
|
{
|
|
|
|
dir: 'es6',
|
|
|
|
format: 'esm'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
outputOptions: {
|
|
|
|
sourcemap: false
|
|
|
|
},
|
|
|
|
inputOptions: {
|
|
|
|
onwarn: (warning, rollupWarn) => {
|
|
|
|
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
|
|
|
rollupWarn(warning)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
main: options.inputFile,
|
|
|
|
...generateInputs(elementComponents)
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
alias({
|
|
|
|
entries: Object.keys(aliases).map(find => {
|
|
|
|
return {
|
|
|
|
find,
|
|
|
|
replacement: aliases[find]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
nodeResolve({
|
|
|
|
preferBuiltins: false,
|
|
|
|
mainFields: ['module', 'browser']
|
|
|
|
}),
|
|
|
|
replace({
|
|
|
|
preventAssignment: true,
|
|
|
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
|
|
}),
|
|
|
|
commonjs(),
|
|
|
|
globals(),
|
|
|
|
progress(),
|
|
|
|
webWorkerLoader(),
|
|
|
|
scss({
|
|
|
|
output: options.sassOutputDir
|
|
|
|
}),
|
|
|
|
terser({
|
|
|
|
compress: true,
|
|
|
|
output: {
|
|
|
|
comments: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
preserveEntrySignatures: false,
|
|
|
|
external: ['crypto'],
|
|
|
|
context: 'window'
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
outputDir: options.outputDir
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
for (const output of buildConfig.outputs) {
|
|
|
|
output.dir = path.join(options.outputDir, output.dir)
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
const inlineConfigs = generateES5BuildConfig(inlineComponents, {
|
|
|
|
outputDir: options.outputDir,
|
|
|
|
aliases
|
|
|
|
})
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
return {
|
|
|
|
buildConfig,
|
|
|
|
inlineConfigs
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|
|
|
|
|
2024-05-08 13:16:23 +02:00
|
|
|
module.exports = generateBuildConfig
|