Package Exports
- @replit/extensions
- @replit/extensions/package.json
- @replit/extensions/react
Readme
Replit Extensions API Client
The Replit Extensions client is a module that allows you to easily interact with the Workspace
- Repository
- NPM Package
- Documentation
- Resources
- API Modules
- React Hooks
- Discord Server
- React Extension Template
- HTML/CSS/JS Extension Template
Installation
npm install @replit/extensions
yarn add @replit/extensions
pnpm add @replit/extensionsUsage
Note: Make sure you have access to the Extensions Developer Beta. If not, you can apply for access here.
- Fork the React Template on Replit and run the Repl
- Use cmd/ctrl + K to open up the command bar
- Hit Manage extensions > Add an extension by URL
- In the sidebar, you should see your extension pop up under Extensions Devtools. Click it to open it.
- Hit each of the buttons in the output to confirm that the extension works.
- Create a simple file creator extension:
import './App.css'
import { useState } from 'react';
import { useReplit } from '@replit/extensions/react';
function App() {
const { status, error, replit } = useReplit(); // Establish the handshake with Replit
const [fileName, setFileName] = useState(""); // File name
const [fileValue, setFileValue] = useState(""); // File content
// Create the file and send a confirmation message
const createFile = async () => {
await replit.fs.writeFile(fileName, fileValue);
await replit.messages.showConfirm("File Created");
}
return (
<main>
<div className="heading">File Creator</div>
{status === "error" ? <div className="error">{error.message}</div> : null}
{status === "loading" ? <div>Loading...</div> : null}
{status === "ready" ?
<div style={{
display: 'flex',
flexDirection: 'column'
}}>
<input
placeholder="File name"
value={fileName}
onChange={e => setFileName(e.target.value)}
/>
<textarea
placeholder="File content"
value={fileValue}
onChange={e => setFileValue(e.target.value)}
rows={5}
/>
<button onClick={createFile}>Create File</button>
</div> : null}
</main>
);
}
export default App;Developer Guide
Repl
- Import this repository onto Replit.
- Configure the
.replitfile (docs) to run thedevscript in package.json (npm run dev). This will build the project with esbuild and run a dev server which opens a webview. - Once built, you can publish the package with
npm publish. Make sure you increment the version. - Update the changelog when publishing.
- Copy the URL from the webview and install it as an extension in your Repl.
Local Development
- Clone this repository with
git clone https://github.com/replit/extensions. - Navigate into the folder with
cd extensions. - Run
npm run devto build the package and run the development server. - Expose localhost to an ngrok link with
ngrok http <port>. - Copy the https ngrok link and install that as an extension (note: some of the filesystem APIs won't behave correctly on localhost)
Help
If you don't understand something in the documentation, have found a bug, or would like to request a feature, you can get support in our discord server.
