Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
kricsleo committed Oct 9, 2022
1 parent 561c751 commit 75af01f
Show file tree
Hide file tree
Showing 53 changed files with 21,440 additions and 45 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
Copyright (c) 2021 Anthony Fu <https://github.com/kricsleo>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 12 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
# unplugin-starter
# unplugin-sentry

[![NPM version](https://img.shields.io/npm/v/unplugin-starter?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-starter)
[![NPM version](https://img.shields.io/npm/v/unplugin-sentry?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-sentry)

Starter template for [unplugin](https://github.com/unjs/unplugin).

## Template Usage

To use this template, clone it down using:

```bash
npx degit antfu/unplugin-starter my-unplugin
```

And do a global replace of `unplugin-starter` with your plugin name.

Then you can start developing your unplugin 🔥

To test your plugin, run: `pnpm run dev`
To release a new version, run: `pnpm run release`
Plugin for Sentry, support webpack & vite & rollup.

## Install

```bash
npm i unplugin-starter
npm i unplugin-sentry
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Starter from 'unplugin-starter/vite'
import unpluginSentry from 'unplugin-sentry/vite'

export default defineConfig({
plugins: [
Starter({ /* options */ }),
unpluginSentry({ /* options */ }),
],
})
```
Expand All @@ -48,11 +33,11 @@ Example: [`playground/`](./playground/)

```ts
// rollup.config.js
import Starter from 'unplugin-starter/rollup'
import unpluginSentry from 'unplugin-sentry/rollup'

export default {
plugins: [
Starter({ /* options */ }),
unpluginSentry({ /* options */ }),
],
}
```
Expand All @@ -68,7 +53,7 @@ export default {
module.exports = {
/* ... */
plugins: [
require('unplugin-starter/webpack')({ /* options */ })
require('unplugin-sentry/webpack')({ /* options */ })
]
}
```
Expand All @@ -82,7 +67,7 @@ module.exports = {
// nuxt.config.js
export default {
buildModules: [
['unplugin-starter/nuxt', { /* options */ }],
['unplugin-sentry/nuxt', { /* options */ }],
],
}
```
Expand All @@ -99,25 +84,12 @@ export default {
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-starter/webpack')({ /* options */ }),
require('unplugin-sentry/webpack')({ /* options */ }),
],
},
}
```

<br></details>

<details>
<summary>esbuild</summary><br>

```ts
// esbuild.config.js
import { build } from 'esbuild'
import Starter from 'unplugin-starter/esbuild'

build({
plugins: [Starter()],
})
```

<br></details>
Support for `esbuild` is welcome!(I'll do it later.)
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "unplugin-starter",
"name": "unplugin-sentry",
"type": "module",
"version": "0.1.0",
"packageManager": "[email protected]",
"description": "Register global imports on demand for Vite and Webpack",
"license": "MIT",
"homepage": "https://github.com/antfu/unplugin-starter#readme",
"homepage": "https://github.com/kricsleo/unplugin-sentry#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/antfu/unplugin-starter.git"
"url": "git+https://github.com/kricsleo/unplugin-sentry.git"
},
"bugs": {
"url": "https://github.com/antfu/unplugin-starter/issues"
"url": "https://github.com/kricsleo/unplugin-sentry/issues"
},
"keywords": [
"unplugin",
Expand Down
4 changes: 4 additions & 0 deletions playground/rollup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
node_modules
package-lock.json
public/bundle*
7 changes: 7 additions & 0 deletions playground/rollup/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2017 [these people](https://github.com/rollup/rollup-starter-app/graphs/contributors)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 changes: 35 additions & 0 deletions playground/rollup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# rollup-starter-app

This repo contains a bare-bones example of how to create an application using Rollup, including importing a module from `node_modules` and converting it from CommonJS.

*See also https://github.com/rollup/rollup-starter-lib*


## Getting started

Clone this repository and install its dependencies:

```bash
git clone https://github.com/rollup/rollup-starter-app
cd rollup-starter-app
npm install

# or
npx degit "rollup/rollup-starter-app" my-app
cd my-app
npm install
```

The `public/index.html` file contains a `<script src='bundle.js'>` tag, which means we need to create `public/bundle.js`. The `rollup.config.js` file tells Rollup how to create this bundle, starting with `src/main.js` and including all its dependencies, including [date-fns](https://date-fns.org).

`npm run build` builds the application to `public/bundle.js`, along with a sourcemap file for debugging.

`npm start` launches a server, using [serve](https://github.com/zeit/serve). Navigate to [localhost:3000](http://localhost:3000).

`npm run watch` will continually rebuild the application as your source files change.

`npm run dev` will run `npm start` and `npm run watch` in parallel.

## License

[MIT](LICENSE).
20 changes: 20 additions & 0 deletions playground/rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "rollup-starter-app",
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.1.0",
"npm-run-all": "^4.1.5",
"rollup": "^2.36.2",
"rollup-plugin-terser": "^7.0.2",
"serve": "^11.3.2"
},
"dependencies": {
"date-fns": "^2.16.1"
},
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w",
"dev": "npm-run-all --parallel start watch",
"start": "serve public"
}
}
21 changes: 21 additions & 0 deletions playground/rollup/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html>
<head lang='en'>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<title>rollup-starter-app</title>

<style>
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
color: #333;
font-weight: 300;
}
</style>
</head>
<body>
<h1>rollup-starter-app</h1>
<p>The time is <span id='time-now'>...</span></p>
<script src='bundle.js'></script>
</body>
</html>
29 changes: 29 additions & 0 deletions playground/rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import Unplugin from '../../dist/rollup'
import { options } from '../../local.test'

// `npm run build` -> `production` is true
// `npm run dev` -> `production` is false
const production = !process.env.ROLLUP_WATCH

export default {
input: 'src/main.js',
output: {
format: 'iife', // immediately-invoked function expression — suitable for <script> tags
sourcemap: true,
dir: 'dist',
},
plugins: [
resolve(), // tells Rollup how to find date-fns in node_modules
commonjs(), // converts date-fns to ES modules
production && terser(), // minify, but only in production
Unplugin({
...options,
deploy: {
env: 'production',
},
}),
],
}
7 changes: 7 additions & 0 deletions playground/rollup/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import update from './update.js';

// even though Rollup is bundling all your files together, errors and
// logs will still point to your original source modules
console.log('if you have sourcemaps enabled in your devtools, click on main.js:5 -->');

update();
8 changes: 8 additions & 0 deletions playground/rollup/src/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import format from 'date-fns/format';

var span = document.querySelector('#time-now');

export default function update() {
span.textContent = format(new Date(), 'h:mm:ssa');
setTimeout(update, 1000);
}
13 changes: 13 additions & 0 deletions playground/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="app"></div>
<a href="/__inspect/module?id=./main.ts&index=2" target="_blank" style="text-decoration: none; margin-top:10px; display: block;">visit /__inspect/ to inspect the intermediate state</a>
<script type="module" src="./main.ts"></script>
</body>
</html>
1 change: 1 addition & 0 deletions playground/vite/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.getElementById('app')!.innerHTML = '__UNPLUGIN__'
12 changes: 12 additions & 0 deletions playground/vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"scripts": {
"dev": "nodemon -w '../src/**/*.ts' -e .ts -x vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^3.1.4",
"vite-plugin-inspect": "^0.7.4"
}
}
14 changes: 14 additions & 0 deletions playground/vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import Unplugin from '../../src/vite'
import { options } from '../../local.test'

export default defineConfig({
plugins: [
Inspect(),
Unplugin(options),
],
build: {
sourcemap: true,
},
})
13 changes: 13 additions & 0 deletions playground/webpack-nuxt/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
Loading

0 comments on commit 75af01f

Please sign in to comment.