1
0
Fork 0
freesewing/packages/components/rollup.config.js
Joost De Cock 1a5b2769aa feat(components): Better snippet support in Draft component
The Draft react component would load the snippets that are part of our
plugin bundle. However, any additional snippets that are created by
plugins would not not get added to the `defs` section, and thus not
be rendered.

This changes the behavior by doing two things:

 - in `core` it adds an SVG object to the renderProps, and makes
   sure to run the `preRender` hook on this SVG object prior to
   returning the renderProps. This way, svg.defs now holds all
   defs, including any that may have been added by custom plugins
 - in the `Draft` component, we no longer add a list of predefined
   snippets to the defs section, but instead just use the svg.defs
   section verbatim. This removes any discrepancies in how SVG
   rendering and React rendering handles the defs section of the
   SVG document, and thus displays snippets.
2020-11-08 18:19:10 +01:00

44 lines
1.4 KiB
JavaScript

import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import { terser } from 'rollup-plugin-terser'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import { name, version, description, author, license } from './package.json'
import components from './src/index.js'
const createConfig = (component, module) => {
return {
input: `./src/${component + '/'}index.js`,
output: {
file: `./${component}/index` + (module ? '.mjs' : '.js'),
format: module ? 'es' : 'cjs',
sourcemap: true,
exports: 'default'
},
plugins: [
babel({
exclude: 'node_modules/**',
babelHelpers: 'bundled'
}),
peerDepsExternal(),
resolve({ modulesOnly: true }),
json(),
terser({
output: {
preamble: `/**\n * ${name} | v${version}\n * ${description}\n * (c) ${new Date().getFullYear()} ${author}\n * @license ${license}\n */`
}
})
]
}
}
const config = []
// When developing, you can use this to only rebuild the components you're working on
let dev = false
let only = ['Draft', 'Workbench']
for (let component of components) {
if (!dev || only.indexOf(component) !== -1) config.push(createConfig(component, false))
// Webpack doesn't handle .mjs very well
//config.push(createConfig(component, true));
}
export default config