From 6dd25d553c5bf7cf841133ddbecd43f4035107b8 Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 18 Jan 2021 14:51:13 +0100 Subject: [PATCH] feat(rollup): create entry point without css --- rollup.config.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 495eca26..552c1164 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,4 @@ +import path from 'path'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import babel from '@rollup/plugin-babel'; @@ -12,7 +13,7 @@ import pkg from './package.json'; const isProd = process.env.NODE_ENV === 'production'; const processEnv = isProd ? 'production' : 'development'; -export default { +const baseConfig = ({ mainFile = pkg.main, moduleFile = pkg.module, extractCss = false } = {}) => ({ input: 'src/index.ts', external: ['react', 'react-dom', /@babel\/runtime/], onwarn(warning, rollupWarn) { @@ -22,13 +23,13 @@ export default { }, output: [ { - file: pkg.main, + file: mainFile, format: 'cjs', sourcemap: true, exports: 'named', }, { - file: pkg.module, + file: moduleFile, format: 'esm', sourcemap: true, exports: 'named', @@ -38,10 +39,13 @@ export default { replace({ __ENV__: JSON.stringify(processEnv), __REACT_FLOW_VERSION__: JSON.stringify(pkg.version), + // this comes from the easy-peasy dependency 'memoizerific' + 'process.env.FORCE_SIMILAR_INSTEAD_OF_MAP': JSON.stringify('true'), }), bundleSize(), postcss({ minimize: isProd, + extract: extractCss, }), babel({ exclude: 'node_modules/**', @@ -56,4 +60,15 @@ export default { include: 'node_modules/**', }), ], -}; +}); + +export default isProd + ? [ + baseConfig(), + baseConfig({ + mainFile: 'dist/nocss/ReactFlow-nocss.js', + moduleFile: 'dist/nocss/ReactFlow-nocss.esm.js', + extractCss: path.resolve('dist/nocss/style.css'), + }), + ] + : baseConfig();