Skip to content

Commit

Permalink
Remove commonjs build from webpack package
Browse files Browse the repository at this point in the history
  • Loading branch information
minevala committed Feb 2, 2023
1 parent 81bf29d commit f5516ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 60 deletions.
1 change: 0 additions & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
81 changes: 22 additions & 59 deletions packages/web-components/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 [
{
Expand All @@ -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),
},
];

0 comments on commit f5516ac

Please sign in to comment.