Skip to content

Commit

Permalink
build: 🔨 Fix rollup config, update package.json & add test project
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmeyer committed Aug 19, 2021
1 parent 3406e60 commit 54d7e69
Show file tree
Hide file tree
Showing 24 changed files with 12,246 additions and 31 deletions.
117 changes: 116 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
{
"name": "figma-react-hooks",
"version": "1.0.0",
"description": "",
"main": "index.js",
"version": "0.1.0",
"description": "Custom React hooks for the available Figma plugin UI actions",
"main": "dist/bundle.js",
"module": "dist/bundle.esm.js",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w"
"dev": "rollup -c -w",
"prepublishOnly": "npm run build"
},
"keywords": [],
"keywords": [
"React",
"Hooks",
"Figma"
],
"author": "Michael Meyer",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0"
"react": "^16.8.0 || ^17.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-typescript": "^8.2.5",
"@types/rollup": "^0.54.0",
"rollup": "^2.56.2",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.3.5"
},
"bugs": {
"url": "https://github.com/mtmeyer/figma-react-hooks/issues"
},
"homepage": {
"url": "https://github.com/mtmeyer/figma-react-hooks#readme"
}
}
30 changes: 21 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
// import resolve from '@rollup/plugin-node-resolve';
import resolve from '@rollup/plugin-node-resolve';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
import autoExternal from 'rollup-plugin-auto-external';
// import autoExternal from 'rollup-plugin-auto-external';

const production = !process.env.ROLLUP_WATCH;
const packageJson = require('./package.json');

export default [
{
input: 'src/index.ts',
output: {
name: 'bundle',
file: 'dist/bundle.js',
format: 'umd'
},
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true
},
{
file: packageJson.module,
format: 'esm',
sourcemap: true
}
],
plugins: [
autoExternal(),
// autoExternal(),
peerDepsExternal(),

typescript({ sourceMap: !production }),
resolve(),

commonjs(),

typescript({ sourceMap: !production }),

// If dev mode, serve and livereload
!production && serve(),
!production && livereload('dist'),
Expand Down
18 changes: 3 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import { useEffect } from 'react';
import useOnMessage from './useOnMessage';
import usePostMessage from './usePostMessage';

export function usePostMessage(object: any, options = '*'): void {
parent.postMessage({ pluginMessage: object }, options);
}

export function useOnMessage(inputFunction?: (data: any) => void): any {
useEffect(() => {
window.onmessage = (event) => {
let data = event.data.pluginMessage;
if (inputFunction) {
inputFunction(data);
}
};
}, []);
}
export { useOnMessage, usePostMessage };
12 changes: 12 additions & 0 deletions src/useOnMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from 'react';

export default function useOnMessage(inputFunction?: (data: any) => void): any {
useEffect(() => {
window.onmessage = (event) => {
let data = event.data.pluginMessage;
if (inputFunction) {
inputFunction(data);
}
};
}, []);
}
3 changes: 3 additions & 0 deletions src/usePostMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function usePostMessage(object: any, options = '*'): void {
parent.postMessage({ pluginMessage: object }, options);
}
4 changes: 4 additions & 0 deletions test-project/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["@babel/plugin-transform-runtime"]
}
Loading

0 comments on commit 54d7e69

Please sign in to comment.