mirror of
https://github.com/jakejarvis/npm-module-template.git
synced 2025-04-26 07:35:23 -04:00
initial commit 🎉
This commit is contained in:
commit
1cbe2b4758
17
.eslintrc.json
Normal file
17
.eslintrc.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"@jakejarvis/eslint-config"
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2015,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"ignorePatterns": [
|
||||||
|
"dist/**",
|
||||||
|
"rollup.config.js"
|
||||||
|
]
|
||||||
|
}
|
20
.github/workflows/ci.yml
vendored
Normal file
20
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '14.x'
|
||||||
|
- run: yarn install --frozen-lockfile
|
||||||
|
- run: yarn lint
|
||||||
|
- run: yarn test
|
||||||
|
- run: yarn build
|
38
.github/workflows/release.yml
vendored
Normal file
38
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
npm:
|
||||||
|
name: Publish to NPM
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
registry-url: https://registry.npmjs.org/
|
||||||
|
- env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
run: |
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
yarn publish
|
||||||
|
|
||||||
|
gpr:
|
||||||
|
name: Publish to GitHub
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
registry-url: https://npm.pkg.github.com/
|
||||||
|
scope: '@jakejarvis'
|
||||||
|
- env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
yarn publish
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
.npmrc
|
||||||
|
.vscode/
|
19
LICENSE
Normal file
19
LICENSE
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2021 Jake Jarvis
|
||||||
|
|
||||||
|
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.
|
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Universal JS Boilerplate
|
||||||
|
|
||||||
|
Just a personal boilerplate to my liking for an Node and/or browser module w/ ESM, CommonJS, and UMD outputs via Babel & Rollup. Ready to publish on NPM and/or GitHub Packages and distibute via unpkg, skypack.dev, etc.
|
||||||
|
|
||||||
|
Probably not very useful to anybody else. 😊
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- [@jakejarvis/dark-mode](https://github.com/jakejarvis/dark-mode)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
55
package.json
Normal file
55
package.json
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"name": "@jakejarvis/my-module",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"author": {
|
||||||
|
"name": "Jake Jarvis",
|
||||||
|
"email": "jake@jarv.is",
|
||||||
|
"url": "https://jarv.is/"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/jakejarvis/my-module.git"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"main": "./dist/my-module.cjs.js",
|
||||||
|
"module": "./dist/my-module.esm.js",
|
||||||
|
"unpkg": "./dist/my-module.min.js",
|
||||||
|
"types": "./dist/my-module.d.ts",
|
||||||
|
"exports": {
|
||||||
|
"require": "./dist/my-module.cjs.js",
|
||||||
|
"import": "./dist/my-module.esm.js",
|
||||||
|
"browser": "./dist/my-module.min.js"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"build": "rollup -c",
|
||||||
|
"lint": "eslint src/**/*.js",
|
||||||
|
"test": "echo \"Tests are important. ;)\"",
|
||||||
|
"prepublishOnly": "run-s clean build"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.15.0",
|
||||||
|
"@babel/preset-env": "^7.15.0",
|
||||||
|
"@jakejarvis/eslint-config": "*",
|
||||||
|
"@rollup/plugin-babel": "^5.3.0",
|
||||||
|
"@rollup/plugin-eslint": "^8.0.1",
|
||||||
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
||||||
|
"eslint": "^7.32.0",
|
||||||
|
"eslint-plugin-compat": "^3.13.0",
|
||||||
|
"eslint-plugin-import": "^2.24.2",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rollup": "^2.56.3",
|
||||||
|
"rollup-plugin-copy": "^3.4.0",
|
||||||
|
"rollup-plugin-filesize": "^9.1.1",
|
||||||
|
"rollup-plugin-terser": "^7.0.2"
|
||||||
|
},
|
||||||
|
"keywords": []
|
||||||
|
}
|
88
rollup.config.js
Normal file
88
rollup.config.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import pkg from "./package.json";
|
||||||
|
import resolve from "@rollup/plugin-node-resolve";
|
||||||
|
import { babel } from "@rollup/plugin-babel";
|
||||||
|
import { terser } from "rollup-plugin-terser";
|
||||||
|
import eslint from "@rollup/plugin-eslint";
|
||||||
|
import filesize from "rollup-plugin-filesize";
|
||||||
|
import copy from "rollup-plugin-copy";
|
||||||
|
|
||||||
|
const banner = `/*! My Module v${pkg.version} */`;
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
// universal (browser and node)
|
||||||
|
input: "src/index.js",
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
name: "MyModule",
|
||||||
|
file: "dist/my-module.js",
|
||||||
|
format: "umd",
|
||||||
|
exports: "named",
|
||||||
|
esModule: false,
|
||||||
|
banner: banner,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "MyModule",
|
||||||
|
file: "dist/my-module.min.js",
|
||||||
|
format: "umd",
|
||||||
|
exports: "named",
|
||||||
|
esModule: false,
|
||||||
|
plugins: [
|
||||||
|
terser({
|
||||||
|
format: {
|
||||||
|
preamble: banner,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
copy({
|
||||||
|
// clearly this isn't really typescript, so we need to manually copy the type definition file
|
||||||
|
targets: [
|
||||||
|
{
|
||||||
|
src: "src/index.d.ts",
|
||||||
|
dest: "dist",
|
||||||
|
rename: "my-module.d.ts",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
resolve(),
|
||||||
|
eslint(),
|
||||||
|
babel({
|
||||||
|
babelHelpers: "bundled",
|
||||||
|
presets: [["@babel/preset-env"]],
|
||||||
|
exclude: ["node_modules/**"],
|
||||||
|
}),
|
||||||
|
filesize(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// modules
|
||||||
|
input: "src/index.js",
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
// ES6 module (import)
|
||||||
|
file: "dist/my-module.esm.js",
|
||||||
|
format: "esm",
|
||||||
|
exports: "named",
|
||||||
|
banner: banner,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// commonjs (require)
|
||||||
|
file: "dist/my-module.cjs.js",
|
||||||
|
format: "cjs",
|
||||||
|
exports: "named",
|
||||||
|
banner: banner,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
resolve(),
|
||||||
|
babel({
|
||||||
|
babelHelpers: "bundled",
|
||||||
|
exclude: ["node_modules/**"],
|
||||||
|
}),
|
||||||
|
filesize(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
1
src/index.d.ts
vendored
Normal file
1
src/index.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export function something(): void;
|
5
src/index.js
Normal file
5
src/index.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const something = function () {
|
||||||
|
console.info("well hello there");
|
||||||
|
};
|
||||||
|
|
||||||
|
export { something };
|
Loading…
x
Reference in New Issue
Block a user