mirror of
https://github.com/jakejarvis/dark-mode.git
synced 2025-04-25 09:35:21 -04:00
switch to microbundle
This commit is contained in:
parent
c62cde5e91
commit
57989cf25f
@ -1,19 +1,16 @@
|
||||
{
|
||||
"extends": [
|
||||
"@jakejarvis/eslint-config",
|
||||
"plugin:compat/recommended",
|
||||
"plugin:import/recommended"
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parser": "@babel/eslint-parser",
|
||||
"parserOptions": {
|
||||
"requireConfigFile": false
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true
|
||||
"browser": true
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"*.d.ts",
|
||||
"dist/**"
|
||||
]
|
||||
}
|
||||
|
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -3,17 +3,17 @@ name: CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
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 build
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
- run: yarn install --frozen-lockfile
|
||||
- run: yarn lint
|
||||
- run: yarn build
|
||||
|
22
.github/workflows/release.yml
vendored
22
.github/workflows/release.yml
vendored
@ -3,20 +3,18 @@ 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
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: yarn install --frozen-lockfile
|
||||
- run: yarn publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
@ -1,8 +1,7 @@
|
||||
# 🌓 Dark Mode Switcheroo™
|
||||
|
||||
[](https://github.com/jakejarvis/dark-mode/actions/workflows/ci.yml)
|
||||
[](https://www.npmjs.com/package/dark-mode-switcheroo)
|
||||
[](LICENSE)
|
||||
[](https://www.npmjs.com/package/dark-mode-switcheroo)
|
||||
|
||||
Very simple CSS dark/light mode toggler with saved preference via local storage & dynamic OS setting detection. Zero dependencies and [only ~500 bytes gzipped!](https://bundlephobia.com/package/dark-mode-switcheroo)
|
||||
|
||||
|
32
package.json
32
package.json
@ -17,41 +17,29 @@
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"main": "./dist/dark-mode.cjs.js",
|
||||
"source": "./src/dark-mode.ts",
|
||||
"main": "./dist/dark-mode.cjs",
|
||||
"module": "./dist/dark-mode.esm.js",
|
||||
"unpkg": "./dist/dark-mode.min.js",
|
||||
"types": "./dist/dark-mode.d.ts",
|
||||
"exports": {
|
||||
"require": "./dist/dark-mode.cjs.js",
|
||||
"require": "./dist/dark-mode.cjs",
|
||||
"import": "./dist/dark-mode.esm.js",
|
||||
"browser": "./dist/dark-mode.min.js"
|
||||
},
|
||||
"types": "./dist/dark-mode.d.ts",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"watch": "rollup -c -w",
|
||||
"build": "microbundle --format cjs,esm,umd --name 'darkMode'",
|
||||
"lint": "eslint .",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.8",
|
||||
"@babel/eslint-parser": "^7.15.8",
|
||||
"@babel/preset-env": "^7.15.8",
|
||||
"@jakejarvis/eslint-config": "*",
|
||||
"@rollup/plugin-babel": "^5.3.0",
|
||||
"@rollup/plugin-commonjs": "^21.0.0",
|
||||
"@rollup/plugin-eslint": "^8.0.1",
|
||||
"@rollup/plugin-node-resolve": "^13.0.5",
|
||||
"builtin-modules": "^3.2.0",
|
||||
"eslint": "^8.0.0",
|
||||
"eslint-plugin-compat": "^3.13.0",
|
||||
"eslint-plugin-import": "^2.25.2",
|
||||
"rollup": "^2.58.0",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
"rollup-plugin-delete": "^2.0.0",
|
||||
"rollup-plugin-filesize": "^9.1.1",
|
||||
"rollup-plugin-node-externals": "^2.2.0",
|
||||
"rollup-plugin-terser": "^7.0.2"
|
||||
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
||||
"@typescript-eslint/parser": "^5.3.1",
|
||||
"eslint": "^8.2.0",
|
||||
"microbundle": "^0.14.1",
|
||||
"typescript": "^4.4.4"
|
||||
},
|
||||
"keywords": [
|
||||
"front-end",
|
||||
|
@ -1,96 +0,0 @@
|
||||
import pkg from "./package.json";
|
||||
import resolve from "@rollup/plugin-node-resolve";
|
||||
import externals from "rollup-plugin-node-externals";
|
||||
import { babel } from "@rollup/plugin-babel";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
import filesize from "rollup-plugin-filesize";
|
||||
import copy from "rollup-plugin-copy";
|
||||
import del from "rollup-plugin-delete";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import eslint from "@rollup/plugin-eslint";
|
||||
|
||||
const exportName = "darkMode";
|
||||
const input = "src/index.js";
|
||||
const banner = `/*! ${pkg.name} v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */`;
|
||||
|
||||
export default [
|
||||
{
|
||||
// universal (browser and node)
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
name: exportName,
|
||||
file: pkg.exports.browser.replace(".min.js", ".js"), // unminified (.js)
|
||||
format: "umd",
|
||||
exports: "named",
|
||||
esModule: false,
|
||||
banner: banner,
|
||||
},
|
||||
{
|
||||
name: exportName,
|
||||
file: pkg.exports.browser, // minified (.min.js)
|
||||
format: "umd",
|
||||
exports: "named",
|
||||
esModule: false,
|
||||
plugins: [
|
||||
terser({
|
||||
output: {
|
||||
preamble: banner,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
del({ targets: "dist/*" }),
|
||||
copy({
|
||||
// clearly this isn't really typescript, so we need to manually copy the type definition file
|
||||
targets: [
|
||||
{
|
||||
src: input.replace(".js", ".d.ts"),
|
||||
dest: "dist",
|
||||
rename: pkg.types.replace("./dist/", ""),
|
||||
},
|
||||
],
|
||||
}),
|
||||
resolve(),
|
||||
commonjs(),
|
||||
eslint(),
|
||||
babel({
|
||||
babelHelpers: "bundled",
|
||||
presets: [["@babel/preset-env"]],
|
||||
exclude: ["node_modules/**"],
|
||||
}),
|
||||
filesize(),
|
||||
],
|
||||
},
|
||||
{
|
||||
// modules
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
// ES6 module (import)
|
||||
file: pkg.exports.import,
|
||||
format: "esm",
|
||||
exports: "named",
|
||||
banner: banner,
|
||||
},
|
||||
{
|
||||
// commonjs (require)
|
||||
file: pkg.exports.require,
|
||||
format: "cjs",
|
||||
exports: "named",
|
||||
banner: banner,
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
externals({ deps: true }),
|
||||
resolve(),
|
||||
babel({
|
||||
babelHelpers: "bundled",
|
||||
exclude: ["node_modules/**"],
|
||||
}),
|
||||
filesize(),
|
||||
],
|
||||
},
|
||||
];
|
@ -1,4 +1,12 @@
|
||||
export function init(options) {
|
||||
export function init(options: {
|
||||
toggle?: Element | null;
|
||||
classes?: { dark: string, light: string };
|
||||
default?: string;
|
||||
storageKey?: string;
|
||||
onInit?: (toggle?: Element | null) => unknown;
|
||||
onUserToggle?: (toggle?: Element | null) => unknown;
|
||||
onChange?: (theme: string, toggle?: Element | null) => unknown;
|
||||
}): void {
|
||||
options = options || {};
|
||||
|
||||
// use a specified element(s) to trigger swap when clicked
|
||||
@ -19,7 +27,7 @@ export function init(options) {
|
||||
let active = defaultTheme === dark;
|
||||
|
||||
// receives a class name and switches <body> to it
|
||||
const activateTheme = function (theme, remember) {
|
||||
const activateTheme = function (theme: string, remember?: boolean) {
|
||||
// optional onChange callback function passed as option
|
||||
if (typeof options.onChange === "function") {
|
||||
options.onChange(theme, toggle);
|
||||
@ -42,7 +50,7 @@ export function init(options) {
|
||||
// user has never clicked the button, so go by their OS preference until/if they do so
|
||||
if (!pref) {
|
||||
// returns media query selector syntax
|
||||
const prefers = function (colorScheme) {
|
||||
const prefers = function (colorScheme: "dark" | "light") {
|
||||
// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
|
||||
return `(prefers-color-scheme: ${colorScheme})`;
|
||||
};
|
9
src/index.d.ts
vendored
9
src/index.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
export function init(options?: {
|
||||
toggle?: Element | null;
|
||||
classes?: { dark: string, light: string };
|
||||
default?: string;
|
||||
storageKey?: string;
|
||||
onInit?: (toggle?: Element | null) => unknown;
|
||||
onUserToggle?: (toggle?: Element | null) => unknown;
|
||||
onChange?: (theme: string, toggle?: Element | null) => unknown;
|
||||
}): void;
|
Loading…
x
Reference in New Issue
Block a user