diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63f38c9..1683f2a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- **BREAKING:** default version of the package doesn't auto-initialize buttons
- remove mixins, defining the code/styles directly in the files
+- use [Vite](https://vitejs.dev/) for building, reducing the devDependencies
+ tree and build times drastically
+ - **BREAKING:** newly built files offer worse browser support
- change code style to [Prettier](https://prettier.io/)
### Removed
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..2cef813
--- /dev/null
+++ b/index.html
@@ -0,0 +1,116 @@
+
+
+
+
+
+ Shareon Demo Page
+
+
+
+
+
+
+
+
+ Shareon Demo Page
+
+ <a>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <button>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <a>
with custom params
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 43c864f..341580b 100644
--- a/package.json
+++ b/package.json
@@ -21,32 +21,32 @@
"email": "me@kytta.dev",
"url": "https://www.kytta.dev"
},
- "main": "./dist/shareon.cjs",
- "module": "./dist/shareon.mjs",
- "unpkg": "./dist/shareon.min.js",
+ "main": "./dist/shareon.umd.js",
+ "unpkg": "./dist/shareon.iife.js",
+ "jsdelivr": "./dist/shareon.iife.js",
+ "module": "./dist/shareon.es.js",
"exports": {
- "require": "./dist/shareon.cjs",
- "import": "./dist/shareon.mjs"
+ ".": {
+ "import": "./dist/shareon.es.js",
+ "require": "./dist/shareon.umd.js"
+ }
},
"files": [
"dist"
],
"scripts": {
- "build": "rollup --config",
- "build:dev": "cross-env NODE_ENV=development rollup --config",
- "dev": "cross-env NODE_ENV=development rollup --config --watch",
+ "build": "pnpm run build:js && pnpm run build:css",
+ "build:js": "vite build",
+ "build:css": "postcss src/shareon.css -o dist/shareon.min.css --map",
+ "dev": "vite",
"lint": "prettier --check . && eslint src/*.js",
"size": "size-limit",
"test": "pnpm run lint && pnpm run build && pnpm run size",
"postversion": "pnpm run build"
},
"devDependencies": {
- "@rollup/plugin-buble": "^0.21.3",
- "@rollup/plugin-strip": "^2.1.0",
"@size-limit/preset-small-lib": "^7.0.5",
"autoprefixer": "^10.4.2",
- "browserslist": "^4.19.1",
- "cross-env": "^7.0.3",
"cssnano": "^5.0.16",
"eslint": "^8.8.0",
"eslint-config-airbnb-base": "^15.0.0",
@@ -55,12 +55,11 @@
"postcss": "^8.4.6",
"postcss-banner": "^4.0.1",
"postcss-calc": "^8.2.3",
+ "postcss-cli": "^9.1.0",
"postcss-css-variables": "^0.18.0",
"prettier": "^2.5.1",
- "rollup": "^2.67.0",
- "rollup-plugin-postcss": "^4.0.2",
- "rollup-plugin-terser": "^7.0.2",
- "size-limit": "^7.0.5"
+ "size-limit": "^7.0.5",
+ "vite": "^2.8.0"
},
"size-limit": [
{
@@ -69,7 +68,7 @@
},
{
"limit": "1 KB",
- "path": "./dist/shareon.mjs"
+ "path": "./dist/shareon.es.js"
}
]
}
diff --git a/postcss.config.js b/postcss.config.js
new file mode 100644
index 0000000..0b0d275
--- /dev/null
+++ b/postcss.config.js
@@ -0,0 +1,21 @@
+const pkg = require("./package.json");
+const bannerText = `${pkg.name} v${pkg.version}`;
+
+module.exports = {
+ map: {
+ inline: false,
+ },
+ plugins: [
+ require("postcss-css-variables"),
+ require("postcss-calc"),
+ require("cssnano")({
+ preset: "default",
+ }),
+ require("autoprefixer"),
+ require("postcss-banner")({
+ banner: bannerText,
+ important: true,
+ inline: true,
+ }),
+ ],
+};
diff --git a/rollup.config.js b/rollup.config.js
deleted file mode 100644
index 07f652c..0000000
--- a/rollup.config.js
+++ /dev/null
@@ -1,91 +0,0 @@
-import { join, resolve } from "path";
-
-import buble from "@rollup/plugin-buble";
-import strip from "@rollup/plugin-strip";
-import postcss from "rollup-plugin-postcss";
-import { terser } from "rollup-plugin-terser";
-
-const autoprefixer = require("autoprefixer");
-const banner = require("postcss-banner");
-const calc = require("postcss-calc");
-const cssnano = require("cssnano");
-const cssVariables = require("postcss-css-variables");
-
-const pkg = require("./package.json");
-
-const isDev =
- process.env.ROLLUP_WATCH || process.env.NODE_ENV === "development";
-const outputDir = resolve(".", "dist");
-const bannerText = `${pkg.name} v${pkg.version}`;
-
-const postcssPlugins = [cssVariables, calc];
-
-if (!isDev) {
- postcssPlugins.push(
- cssnano({
- preset: "default",
- }),
- autoprefixer(),
- banner({
- banner: bannerText,
- important: true,
- inline: true,
- })
- );
-}
-
-const getPlugins = (css) => [
- css &&
- postcss({
- extract: resolve(join(outputDir, "shareon.min.css")),
- plugins: postcssPlugins,
- }),
- !isDev &&
- strip({
- debugger: true,
- include: ["**/*.js"],
- functions: ["console.log", "console.debug", "assert.*"],
- sourceMap: false,
- }),
- !isDev &&
- buble({
- transforms: {
- modules: false,
- },
- }),
-];
-
-const getOutput = (baseDir) => {
- const defaultParameters = {
- name: pkg.name,
- exports: "default",
- };
-
- return [
- {
- ...defaultParameters,
- format: "iife",
- file: join(baseDir, `${pkg.name}${isDev ? "" : ".min"}.js`),
- plugins: isDev ? [] : [terser({ output: { comments: /^!/ } })],
- banner: `/*! ${bannerText} */`,
- },
- !isDev && {
- ...defaultParameters,
- format: "cjs",
- file: join(baseDir, `${pkg.name}.cjs`),
- banner: `/*! ${bannerText} */`,
- },
- !isDev && {
- ...defaultParameters,
- format: "esm",
- file: join(baseDir, `${pkg.name}.mjs`),
- banner: `/*! ${bannerText} */`,
- },
- ];
-};
-
-export default {
- input: join(__dirname, "src", "index.js"),
- output: getOutput(outputDir),
- plugins: getPlugins(true),
-};
diff --git a/src/index.js b/src/index.js
index 108922a..7439056 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,5 +1,4 @@
import initializeShareon from "./shareon";
-import "./shareon.css";
// TODO: update README
const s = document.currentScript;
diff --git a/vite.config.js b/vite.config.js
new file mode 100644
index 0000000..da82255
--- /dev/null
+++ b/vite.config.js
@@ -0,0 +1,24 @@
+import { defineConfig } from "vite";
+import * as path from "path";
+import pkg from "./package.json";
+
+export default defineConfig({
+ esbuild: {
+ minify: true,
+ },
+ build: {
+ sourcemap: true,
+ target: "esnext",
+ minify: "terser",
+ lib: {
+ entry: path.resolve("./src/index.js"),
+ name: "Shareon",
+ formats: ["es", "umd", "iife"],
+ },
+ rollupOptions: {
+ output: {
+ banner: `/*! ${pkg.name} v${pkg.version} */`,
+ },
+ },
+ },
+});