papua
Setup and build modern web applications with Rspack, TypeScript, React, ESLint, Prettier and Vitest all without the need for any configuration at all.
⚠️ With Version 4.0.0 the plugin switches from webpack to Rspack, while largely compatible some migration might be necessary, see details in the v4.0.0 Release.
Installation
New Project
npm init now papua
npm init now papua ./my-project
npm init now papua . javascript
Replace npm init with bun create if you're already living in the future 🚀
The following templates are available:
- default (TS + React)
- javascript (JS + React)
- pwa (TS + React + Progressive Web App) Demo
- website (TS + React + MobX + Stitches)
- serverless (JS + React + Serverless Function)
npm init now papua [destination-directory] [template]
Existing Project
npm i papua
This will automatically adapt your package.json configuration to work with papua. When using Bun make sure to add papua as a trustedDependency as this plugin relies on postinstall to generate configurations during installation.
Usage
npm start | npx papua start [--port <number>] [--headless]
Builds the application and opens it in the browser. Optionally a port can be set and the --headless flag won't open the page in a browser automatically.
npm test | npx papua test
Run tests if there are any.
npx papua build
Builds the application for production. A production build will only be created if there are no lint errors and all tests have passed.
npx papua lint
Lints the code and prints errors.
npx papua serve [--port <number>] [--open]
Builds the production assets and serves them. Can be configured through the papua.serve property in package.json see Serve for available options.
Arguments: --open open in default browser, --port 5000 specify a port.
npx papua eject [--template <html | rspack>] [--file <name>]
Eject certain files to allow for more fine grained configuration. If no default values are provided the plugin will prompt for values. The following templates are available:
- HTML (index.html)
- Rspack (rspack.config.js - file cannot be set)
npx papua watch
Builds application in watch mode for development without opening it in the browser.
Configuration
Most of the default configurations can easily be extended. To do that add
a papua property to your package.json with the following options available:
{
"$schema": "https://raw.githubusercontent.com/tobua/papua/main/schema.json",
"name": "my-app",
"papua": {
output: 'build',
typescript: true,
react: true,
test: 'spec',
entry: 'another.tsx',
entry: ['another.js', 'several.jsx'],
entry: { main: './index.js', separate: ['./chunk.js', 'second.js'] },
publicPath: '/app',
publicPath: '/',
title: 'My papua App',
html: { template: 'page.html', filename: 'modern.html' },
icon: 'my-favicon.ico',
icon: 'logo.png',
icon: '../logo.png',
hash: false,
root: false,
sourceMap: true,
serve: {
cleanUrls: false
},
gitignore: ['test/fixture'],
prettierIgnore: ['test'],
esVersion: 'browserslist',
envVariables: ['MY_API_TOKEN'],
cypress: {
defaultCommandTimeout: 6000
},
injectManifest: {
exclude: ['extension/dist/*']
},
injectManifest: false,
jsconfig: {},
tsconfig: {
compilerOptions: {
removeComments: true
}
}
}
}
JavaScript / TypeScript
index.js / index.ts / index.jsx / index.tsx
If there is a index.ts / index.tsx file available in the root the project will be configured for TypeScript.
jsconfig.json / tsconfig.json
One of these files will automatically be created extending the default configuration. Options added to package.json will automatically be added. However, additions to the file can also be made manually and committed by removing the file from .gitignore if desired.
Template
index.html
If available papua will look for a HTML template in index.html and use a default fallback if none is available. Use the package.json → papua → html option to configure the template to look for and other options passed to builtins.html. Run npx papua eject --template html to place the default template in the root to make your own edits.
Rspack
rspack.config.js
A rspack configuration file can be added in the root. This configuration will then be merged with the default configuration. If a function is exported the default configuration will be received with the mode as a parameter. Run npx papua eject --template rspack to generate an empty rspack.config.js file in the project root where the configuration can be edited.
import { join } from 'path'
export default (configuration, isDevelopment) => ({
devServer: {
onBeforeSetupMiddleware: (devServer) => {
devServer.app.get('/say-hello', async (request, response) => {
response.json({
hello: 'world',
})
})
},
},
})
export const after = (configuration) => {
configuration.module.rules.splice(2, 1)
return configuration
}
Deployment
To deploy a papua to Vercel import the repository and ensure Other Frameworks is selected as the preset. Then override the build command with npx papua build and set the output folder to dist.