From f5516aca24fdd8ab577dafee1982b0d6156e2573 Mon Sep 17 00:00:00 2001 From: Mika Nevalainen Date: Thu, 2 Feb 2023 14:48:37 +0200 Subject: [PATCH] Remove commonjs build from webpack package --- packages/web-components/package.json | 1 - packages/web-components/rollup.config.js | 81 +++++++----------------- 2 files changed, 22 insertions(+), 60 deletions(-) diff --git a/packages/web-components/package.json b/packages/web-components/package.json index 1af64ee874..2a9554cf0e 100644 --- a/packages/web-components/package.json +++ b/packages/web-components/package.json @@ -3,7 +3,6 @@ "version": "2.10.0", "description": "Web components for the Helsinki Design System", "homepage": "https://github.com/City-of-Helsinki/helsinki-design-system#readme", - "main": "./cjs/index.js", "module": "index.js", "types": "./index.d.ts", "scripts": { diff --git a/packages/web-components/rollup.config.js b/packages/web-components/rollup.config.js index ed8b2440ae..c86d4424c2 100644 --- a/packages/web-components/rollup.config.js +++ b/packages/web-components/rollup.config.js @@ -1,4 +1,3 @@ -import fs from 'fs'; import includePaths from 'rollup-plugin-includepaths'; import resolve from '@rollup/plugin-node-resolve'; import ts from 'rollup-plugin-ts'; @@ -16,55 +15,7 @@ const processor = postcss( }), ); -const insertCssCjs = () => { - return { - name: 'insert-css-cjs', - closeBundle: () => { - fs.appendFileSync( - `${__dirname}/lib/cjs/index.js`, - `var hdsStyles = require("./index.css-text"); exports.hdsStyles = hdsStyles;`, - ); - }, - }; -}; - const extensions = ['.js', '.ts']; -const external = ['postcss', 'lodash.uniqueid', 'lodash.isequal', 'lodash.isfunction', 'lodash.toString']; - -const getExternal = (format) => (format === 'esm' ? [...external, /@babel\/runtime/] : external); - -const getPlugins = (format) => { - const babelPlugin = - format === 'esm' && - babel({ - babelHelpers: 'runtime', - exclude: 'node_modules/**', - extensions, - }); - - const plugins = [ - includePaths({ paths: ['src'], extensions }), - resolve(), - ts(), - babelPlugin, - commonjs({ include: ['../../node_modules/**', 'node_modules/**'] }), - litcss({ - include: ['/**/*.css', '/**/*.scss'], - transform: (css, { filePath }) => processor.process(css, { from: filePath }).then((res) => res.css), - }), - ]; - - if (format === 'cjs') { - plugins.push(insertCssCjs()); - } - - return plugins; -}; - -const getConfig = (format, extractCSS) => ({ - plugins: getPlugins(format, extractCSS), - external: getExternal(format), -}); export default [ { @@ -81,16 +32,28 @@ export default [ exports: 'named', }, ], - ...getConfig('esm'), - }, - { - input: ['src/index.ts'], - output: [ - { - dir: 'lib/cjs', - format: 'cjs', - }, + plugins: [ + includePaths({ paths: ['src'], extensions }), + resolve(), + ts(), + babel({ + babelHelpers: 'runtime', + exclude: 'node_modules/**', + extensions, + }), + commonjs({ include: ['../../node_modules/**', 'node_modules/**'] }), + litcss({ + include: ['/**/*.css', '/**/*.scss'], + transform: (css, { filePath }) => processor.process(css, { from: filePath }).then((res) => res.css), + }), + ], + external: [ + 'postcss', + 'lodash.uniqueid', + 'lodash.isequal', + 'lodash.isfunction', + 'lodash.toString', + '@babel/runtime', ], - ...getConfig('cjs', false), }, ];