Skip to content

Commit f28cfcf

Browse files
committed
Add rollup for plugin build
1 parent 638baa1 commit f28cfcf

14 files changed

Lines changed: 477 additions & 73 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea/
22
.DS_Store
33
.vscode/
4+
.vsls.json
45

56
# @spotify/web-script build output
67
cjs/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'rollup-plugin-image-files';

packages/cli/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"@types/react-dev-utils": "^9.0.4",
3434
"@types/recursive-readdir": "^2.2.0",
3535
"@types/tar": "^4.0.3",
36+
"@types/rollup-plugin-peer-deps-external": "2.2.0",
37+
"@types/rollup-plugin-postcss": "2.0.0",
3638
"@types/webpack": "^4.41.7",
3739
"@types/webpack-dev-server": "^3.10.0",
3840
"del": "^5.1.0",
@@ -46,6 +48,8 @@
4648
"dependencies": {
4749
"@lerna/package-graph": "^3.18.5",
4850
"@lerna/project": "^3.18.0",
51+
"@rollup/plugin-commonjs": "^11.0.2",
52+
"@rollup/plugin-node-resolve": "^7.1.1",
4953
"@spotify/web-scripts": "^6.0.0",
5054
"chokidar": "^3.3.1",
5155
"commander": "^4.1.1",
@@ -60,6 +64,11 @@
6064
"react-scripts": "^3.4.0",
6165
"recursive-readdir": "^2.2.2",
6266
"replace-in-file": "^5.0.2",
67+
"rollup": "^2.1.0",
68+
"rollup-plugin-image-files": "^1.4.2",
69+
"rollup-plugin-peer-deps-external": "^2.2.2",
70+
"rollup-plugin-postcss": "^2.5.0",
71+
"rollup-plugin-typescript2": "^0.26.0",
6372
"ts-loader": "^6.2.1",
6473
"webpack": "^4.41.6",
6574
"webpack-dev-server": "^3.10.3"
@@ -72,7 +81,7 @@
7281
],
7382
"nodemonConfig": {
7483
"watch": "./src",
75-
"exec": "ts-node",
84+
"exec": "ts-node ./src",
7685
"ext": "ts"
7786
}
7887
}

packages/cli/src/commands/plugin/assets.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ declare module '*.module.sass' {
9494
const classes: { readonly [key: string]: string };
9595
export default classes;
9696
}
97+
98+
declare module 'rollup-plugin-image-files' {
99+
export default function image(): any;
100+
}

packages/cli/src/commands/plugin/build.ts

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Command } from 'commander';
18-
import fs from 'fs-extra';
19-
import path from 'path';
20-
import recursive from 'recursive-readdir';
21-
import { run } from '../../helpers/run';
17+
const rollup = require('rollup'); // "import" is not working for some reason...
18+
import rollupConfig from './rollup.config';
2219

23-
const copyStaticAssets = async () => {
24-
const pluginRoot = fs.realpathSync(process.cwd());
25-
const source = path.resolve(pluginRoot, 'src');
26-
const destination = path.resolve(pluginRoot, 'dist', 'cjs');
27-
const assetFiles = await recursive(source, [
28-
'**/*.tsx',
29-
'**/*.ts',
30-
'**/*.js',
31-
]);
32-
assetFiles.forEach(file => {
33-
const fileToBeCopied = file.replace(source, destination);
34-
const dirForFileToBeCopied = path.dirname(fileToBeCopied);
35-
fs.ensureDirSync(dirForFileToBeCopied);
36-
fs.copyFileSync(file, file.replace(source, destination).toString());
37-
});
38-
};
39-
40-
export default async (cmd: Command) => {
41-
const args = [
42-
'--outDir',
43-
'dist/cjs',
44-
'--noEmit',
45-
'false',
46-
'--module',
47-
'CommonJS',
48-
];
49-
50-
if (cmd.watch) {
51-
args.push('--watch');
52-
}
20+
export default async () => {
21+
const inputOptions = {
22+
input: rollupConfig.input,
23+
plugins: rollupConfig.plugins,
24+
};
25+
const outputOptions = rollupConfig.output;
5326

54-
await copyStaticAssets();
55-
await run('tsc', args);
27+
const bundle = await rollup.rollup(inputOptions);
28+
await bundle.generate(outputOptions);
29+
await bundle.write(outputOptions);
5630
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2020 Spotify AB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
18+
import typescript from 'rollup-plugin-typescript2'; // @rollup/plugin-typescript
19+
import commonjs from '@rollup/plugin-commonjs';
20+
import resolve from '@rollup/plugin-node-resolve';
21+
import postcss from 'rollup-plugin-postcss';
22+
import image from 'rollup-plugin-image-files';
23+
24+
export default {
25+
input: 'src/index.ts',
26+
output: {
27+
file: 'build/index.esm.js',
28+
format: 'esm',
29+
sourcemap: true,
30+
},
31+
32+
plugins: [
33+
peerDepsExternal(),
34+
resolve(),
35+
commonjs({
36+
include: ['node_modules/**', '../../node_modules/**'],
37+
exclude: ['**/*.stories.js'],
38+
}),
39+
postcss(),
40+
image(),
41+
typescript(),
42+
],
43+
};

packages/cli/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,6 @@ process.on('unhandledRejection', rejection => {
143143
});
144144

145145
main(process.argv);
146-
// main([process.argv[0], process.argv[1], '--version']);
146+
// process.chdir('../../plugins/welcome');
147+
// console.log(`DEBUG: ${process.cwd()}`);
148+
// main([process.argv[0], process.argv[1], 'plugin:build']);
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@backstage/plugin-{{id}}",
33
"version": "{{version}}",
4-
"main": "dist/cjs/index.js",
5-
"types": "dist/cjs/index.d.ts",
4+
"main": "build/index.esm.js",
5+
"types": "build/index.d.ts",
66
"license": "Apache-2.0",
77
"private": true,
88
"scripts": {
@@ -12,11 +12,20 @@
1212
},
1313
"devDependencies": {
1414
"@backstage/cli": "^{{version}}",
15+
"@testing-library/jest-dom": "^4.2.4",
16+
"@testing-library/react": "^9.3.2",
17+
"@testing-library/user-event": "^7.1.2",
18+
"@types/jest": "^24.0.0",
19+
"@types/node": "^12.0.0",
1520
"@types/testing-library__jest-dom": "5.0.2",
1621
"jest-fetch-mock": "^3.0.3"
1722
},
18-
"dependencies": {
19-
"@backstage/core": "^{{version}}",
20-
"@material-ui/lab": "4.0.0-alpha.45"
23+
"peerDependencies": {
24+
"@backstage/core": "^0.1.0",
25+
"@material-ui/core": "^4.9.1",
26+
"@material-ui/icons": "^4.9.1",
27+
"@material-ui/lab": "4.0.0-alpha.45",
28+
"react": "16.13.1",
29+
"react-dom": "16.13.1"
2130
}
2231
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["src"]
3+
"include": ["src"],
4+
"compilerOptions": {
5+
"module": "es6"
6+
}
47
}

plugins/home-page/package.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"name": "@backstage/plugin-home-page",
33
"version": "0.1.1-alpha.0",
4-
"main": "dist/cjs/index.js",
5-
"types": "dist/cjs/index.d.ts",
6-
"private": true,
4+
"module": "build/index.esm.js",
5+
"types": "build/index.d.ts",
6+
"license": "Apache-2.0",
7+
"private": false,
8+
"scripts": {
9+
"build": "backstage-cli build-cache -- backstage-cli plugin:build",
10+
"lint": "backstage-cli lint",
11+
"test": "backstage-cli test"
12+
},
713
"devDependencies": {
814
"@backstage/cli": "^0.1.1-alpha.0",
915
"@backstage/core": "^0.1.1-alpha.0",
@@ -18,10 +24,12 @@
1824
"react": "^16.12.0",
1925
"react-dom": "^16.12.0"
2026
},
21-
"scripts": {
22-
"build": "backstage-cli build-cache -- backstage-cli plugin:build",
23-
"lint": "backstage-cli lint",
24-
"test": "backstage-cli test"
25-
},
26-
"license": "Apache-2.0"
27+
"peerDependencies": {
28+
"@material-ui/core": "^4.9.1",
29+
"@material-ui/icons": "^4.9.1",
30+
"@material-ui/lab": "4.0.0-alpha.45",
31+
"@backstage/core": "^0.1.0",
32+
"react": "16.13.1",
33+
"react-dom": "16.13.1"
34+
}
2735
}

0 commit comments

Comments
 (0)