Skip to content

Commit 3fccd36

Browse files
Merge pull request #3 from csstools/shared-rollup-config
shared rollup config
2 parents 6310497 + ad2a7ab commit 3fccd36

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

rollup/default.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import babel from '@rollup/plugin-babel';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import path from 'path';
4+
import { nodeResolve } from '@rollup/plugin-node-resolve';
5+
import { terser } from 'rollup-plugin-terser';
6+
7+
export default [
8+
{
9+
input: 'src/index.js',
10+
output: [
11+
{ file: 'dist/index.cjs', format: 'cjs', sourcemap: true, exports: 'auto' },
12+
{ file: 'dist/index.mjs', format: 'esm', sourcemap: true, exports: 'auto' },
13+
],
14+
onwarn: (warning) => {
15+
// Silence circular dependency warning for postcss-values-parsers package
16+
if (
17+
warning.code === 'CIRCULAR_DEPENDENCY' &&
18+
warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1
19+
) {
20+
return;
21+
}
22+
23+
console.warn(`(!) ${warning.message}`);
24+
},
25+
plugins: [
26+
babel({
27+
babelHelpers: 'bundled',
28+
exclude: 'node_modules/**',
29+
presets: [
30+
['@babel/preset-env', {
31+
corejs: 3,
32+
loose: true,
33+
modules: false,
34+
targets: { node: 12 },
35+
useBuiltIns: 'usage',
36+
}],
37+
],
38+
}),
39+
terser(),
40+
],
41+
},
42+
{
43+
input: 'src/cli.js',
44+
output: [
45+
{ file: 'dist/cli.mjs', format: 'esm', sourcemap: false },
46+
],
47+
onwarn: (warning) => {
48+
// Silence circular dependency warning for postcss-values-parsers package
49+
if (
50+
warning.code === 'CIRCULAR_DEPENDENCY' &&
51+
warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1
52+
) {
53+
return;
54+
}
55+
56+
console.warn(`(!) ${warning.message}`);
57+
},
58+
plugins: [
59+
commonjs(),
60+
nodeResolve({
61+
rootDir: path.join(process.cwd(), '..', '..'),
62+
}),
63+
babel({
64+
babelHelpers: 'bundled',
65+
exclude: 'node_modules/**',
66+
presets: [
67+
['@babel/preset-env', {
68+
corejs: 3,
69+
loose: true,
70+
modules: false,
71+
targets: { node: 12 },
72+
useBuiltIns: 'usage',
73+
}],
74+
],
75+
}),
76+
terser(),
77+
addHashBang(),
78+
],
79+
},
80+
];
81+
82+
function addHashBang () {
83+
return {
84+
name: 'add-hash-bang',
85+
renderChunk (code) {
86+
const updatedCode = `#!/usr/bin/env node\n\n${code}`;
87+
88+
return updatedCode;
89+
},
90+
};
91+
}

rollup/default.ts.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import babel from '@rollup/plugin-babel';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import path from 'path';
4+
import typescript from '@rollup/plugin-typescript';
5+
import { nodeResolve } from '@rollup/plugin-node-resolve';
6+
import { terser } from 'rollup-plugin-terser';
7+
8+
export default [
9+
{
10+
input: 'src/index.ts',
11+
output: [
12+
{ file: 'dist/index.cjs', format: 'cjs', sourcemap: true, exports: 'auto' },
13+
{ file: 'dist/index.mjs', format: 'esm', sourcemap: true, exports: 'auto' },
14+
],
15+
external: [
16+
'postcss-values-parser',
17+
],
18+
plugins: [
19+
typescript({ tsconfig: './tsconfig.json' }),
20+
babel({
21+
babelHelpers: 'bundled',
22+
exclude: 'node_modules/**',
23+
presets: [
24+
['@babel/preset-env', {
25+
corejs: 3,
26+
loose: true,
27+
modules: false,
28+
targets: { node: 12 },
29+
useBuiltIns: 'usage',
30+
}],
31+
],
32+
}),
33+
terser(),
34+
],
35+
},
36+
{
37+
input: 'src/cli.ts',
38+
output: [
39+
{ file: 'dist/cli.mjs', format: 'esm', sourcemap: false },
40+
],
41+
onwarn: (warning) => {
42+
// Silence circular dependency warning for postcss-values-parsers package
43+
if (
44+
warning.code === 'CIRCULAR_DEPENDENCY' &&
45+
warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1
46+
) {
47+
return;
48+
}
49+
50+
console.warn(`(!) ${warning.message}`);
51+
},
52+
plugins: [
53+
typescript({ tsconfig: './tsconfig.json' }),
54+
commonjs(),
55+
nodeResolve({
56+
rootDir: path.join(process.cwd(), '..', '..'),
57+
}),
58+
babel({
59+
babelHelpers: 'bundled',
60+
exclude: 'node_modules/**',
61+
presets: [
62+
['@babel/preset-env', {
63+
corejs: 3,
64+
loose: true,
65+
modules: false,
66+
targets: { node: 12 },
67+
useBuiltIns: 'usage',
68+
}],
69+
],
70+
}),
71+
terser(),
72+
addHashBang(),
73+
],
74+
},
75+
];
76+
77+
function addHashBang () {
78+
return {
79+
name: 'add-hash-bang',
80+
renderChunk (code) {
81+
const updatedCode = `#!/usr/bin/env node\n\n${code}`;
82+
83+
return updatedCode;
84+
},
85+
};
86+
}

0 commit comments

Comments
 (0)