diff --git a/package-lock.json b/package-lock.json index 443583ba..6adc4d00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "version": "2.1.4", "license": "MIT", "dependencies": { - "formeo-i18n": "^2.1.3", + "@draggable/formeo-languages": "^3.1.3", + "@draggable/i18n": "^1.0.7", "lodash": "^4.17.21", - "mi18n": "^1.0.2", "sortablejs": "^1.15.3" }, "devDependencies": { @@ -547,6 +547,19 @@ "kuler": "^2.0.0" } }, + "node_modules/@draggable/formeo-languages": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@draggable/formeo-languages/-/formeo-languages-3.1.3.tgz", + "integrity": "sha512-DNYSxShxCrmd1Am0vqQsFGHSySwcUTJEi5hk87oY3e4QqEi5AzoZOT30e9RKO+x+tBsbLEKNgI3Flhz6H0wheA==", + "dependencies": { + "mi18n": "^1.0.3" + } + }, + "node_modules/@draggable/i18n": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@draggable/i18n/-/i18n-1.0.7.tgz", + "integrity": "sha512-Tw0YX27smQCrwFEtVwFVmeCLvjdwtxUSnSiYSbl/xakC0CZF9FZY68Ua/ULLArPh8I9hk8G9sN13V5eqnig63w==" + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -2340,7 +2353,6 @@ "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "dev": true, - "license": "ISC", "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -2469,7 +2481,6 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", "dev": true, - "license": "MIT", "engines": { "node": ">=8" }, @@ -2611,7 +2622,6 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "dev": true, - "license": "MIT", "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -4130,14 +4140,6 @@ "node": ">= 6" } }, - "node_modules/formeo-i18n": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/formeo-i18n/-/formeo-i18n-2.1.3.tgz", - "integrity": "sha512-fFaE0FzhUrhKhL8u3b1TiirffflIq2RQBLXzKvO/Q2OlqWmmQxtvv78Htfh8xQV1qnvmfyVzV8mt72DdihEeVQ==", - "engines": { - "node": ">=10" - } - }, "node_modules/from2": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", @@ -4873,7 +4875,6 @@ "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, - "license": "MIT", "dependencies": { "binary-extensions": "^2.0.0" }, @@ -5827,10 +5828,9 @@ } }, "node_modules/mi18n": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mi18n/-/mi18n-1.0.2.tgz", - "integrity": "sha512-amRuUVYd1VpZWPcjCtzZ9qKrBlAC/tzb44CdWpDphWXUzK8SBZ0kmwfsM3INfOQNWWAtAzwmsjZMYbBxB4WZ4A==", - "license": "MIT" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/mi18n/-/mi18n-1.0.3.tgz", + "integrity": "sha512-1OhxKYEgN/BNiMX1Idlyoir+mEYoLLo7Rfeo+89hdOtbUs3PyCIuBoMcfgHSjMjHgs7e7xbRovd6lJq8hLh5mA==" }, "node_modules/micromatch": { "version": "4.0.8", @@ -6027,7 +6027,6 @@ "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true, - "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -10005,7 +10004,6 @@ "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, - "license": "MIT", "dependencies": { "picomatch": "^2.2.1" }, @@ -12158,7 +12156,6 @@ "resolved": "https://registry.npmjs.org/vite-plugin-static-copy/-/vite-plugin-static-copy-2.0.0.tgz", "integrity": "sha512-b/quFjTUa/RY9t3geIyeeT2GtWEoRI0GawYFFjys5iMLGgVP638NTGu0RoMjwmi8MoZZ3BQw4OQvb1GpVcXZDA==", "dev": true, - "license": "MIT", "dependencies": { "chokidar": "^3.5.3", "fast-glob": "^3.2.11", diff --git a/package.json b/package.json index 1fb889e1..9955163d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,16 @@ "name": "formeo", "version": "2.1.4", "type": "module", - "main": "dist/formeo.min.js", + "main": "dist/formeo.cjs.js", + "module": "dist/formeo.es.js", + "unpkg": "dist/formeo.umd.js", + "exports": { + ".": { + "import": "./dist/formeo.es.js", + "require": "./dist/formeo.cjs.js", + "default": "./dist/formeo.umd.js" + } + }, "files": [ "dist/*", "demo/**/*" @@ -55,10 +64,9 @@ "scripts": { "dev": "vite", "preview": "vite preview", - "analyze": "webpack --mode production -p --progress --config tools/webpack.config --analyze", - "build": "npm-run-all -p build:icons build:formeo build:demo", - "build:formeo": "vite build --mode lib", - "build:formeo:watch": "npm run build:formeo -- --watch", + "build:lib": "vite build --config vite.config.lib.mjs", + "build": "npm-run-all -p build:icons build:demo", + "prebuild": "npm run build:lib", "build:demo": "vite build --mode demo", "build:demo:watch": "vite build --mode demo --watch", "build:icons": "node ./tools/generate-sprite", @@ -68,6 +76,7 @@ "test:ci": "yarn test --coverage", "start": "npm-run-all build:icons dev", "semantic-release": "semantic-release --ci --debug", + "copy:lang": "node ./tools/copy-directory.mjs ./node_modules/formeo-i18n/dist/lang ./src/demo/assets/lang", "travis-deploy-once": "travis-deploy-once --pro", "prepush": "yarn test", "defaults": "webpack-defaults" @@ -92,9 +101,9 @@ "vite-plugin-static-copy": "^2.0.0" }, "dependencies": { - "formeo-i18n": "^2.1.3", + "@draggable/formeo-languages": "^3.1.3", + "@draggable/i18n": "^1.0.7", "lodash": "^4.17.21", - "mi18n": "^1.0.2", "sortablejs": "^1.15.3" }, "release": { diff --git a/src/lib/js/common/actions.js b/src/lib/js/common/actions.js index 8c769e46..299d7daf 100644 --- a/src/lib/js/common/actions.js +++ b/src/lib/js/common/actions.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import { SESSION_FORMDATA_KEY, CONDITION_TEMPLATE } from '../constants.js' import { identity, sessionStorage } from './utils/index.mjs' import events from './events.js' diff --git a/src/lib/js/common/dom.js b/src/lib/js/common/dom.js index 5d0dc5f9..1dcc42e1 100644 --- a/src/lib/js/common/dom.js +++ b/src/lib/js/common/dom.js @@ -1,5 +1,5 @@ import h, { forEach } from './helpers.mjs' -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import animate from './animation.js' import Components from '../components/index.js' import { uuid, componentType, merge } from './utils/index.mjs' @@ -735,7 +735,11 @@ class DOM { removeClasses(nodeList, className) { const removeClass = { string: elem => elem.classList.remove(className), - array: elem => className.forEach(name => elem.classList.remove(name)), + array: elem => { + for (const name of className) { + elem.classList.remove(name) + } + }, } removeClass.object = removeClass.string // handles regex map h.forEach(nodeList, removeClass[this.childType(className)]) @@ -750,7 +754,11 @@ class DOM { addClasses(nodeList, className) { const addClass = { string: elem => elem.classList.add(className), - array: elem => className.forEach(name => elem.classList.add(name)), + array: elem => { + for (const name of className) { + elem.classList.add(name) + } + }, } h.forEach(nodeList, addClass[this.childType(className)]) } diff --git a/src/lib/js/components/autocomplete.js b/src/lib/js/components/autocomplete.js index a427bbca..d7ba931c 100644 --- a/src/lib/js/components/autocomplete.js +++ b/src/lib/js/components/autocomplete.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import animate from '../common/animation.js' import dom from '../common/dom.js' import Components from './index.js' diff --git a/src/lib/js/components/columns/column.js b/src/lib/js/components/columns/column.js index 941871ab..6542f4e5 100644 --- a/src/lib/js/components/columns/column.js +++ b/src/lib/js/components/columns/column.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Sortable from 'sortablejs' import Component from '../component.js' import h from '../../common/helpers.mjs' diff --git a/src/lib/js/components/controls/control.js b/src/lib/js/components/controls/control.js index abc8ec04..05a31012 100644 --- a/src/lib/js/components/controls/control.js +++ b/src/lib/js/components/controls/control.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import dom from '../../common/dom.js' import { fetchDependencies } from '../../common/loaders.js' import { uuid } from '../../common/utils/index.mjs' diff --git a/src/lib/js/components/controls/form/button.js b/src/lib/js/components/controls/form/button.js index f70598bd..9240dea1 100644 --- a/src/lib/js/components/controls/form/button.js +++ b/src/lib/js/components/controls/form/button.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class ButtonControl extends Control { diff --git a/src/lib/js/components/controls/form/checkbox-group.js b/src/lib/js/components/controls/form/checkbox-group.js index 6f9b15ba..99878b44 100644 --- a/src/lib/js/components/controls/form/checkbox-group.js +++ b/src/lib/js/components/controls/form/checkbox-group.js @@ -1,5 +1,5 @@ import { generateOptionConfig } from './shared.js' -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class CheckboxGroupControl extends Control { diff --git a/src/lib/js/components/controls/form/input.date.js b/src/lib/js/components/controls/form/input.date.js index 9d640e11..61bc1f24 100644 --- a/src/lib/js/components/controls/form/input.date.js +++ b/src/lib/js/components/controls/form/input.date.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class DateControl extends Control { diff --git a/src/lib/js/components/controls/form/input.file.js b/src/lib/js/components/controls/form/input.file.js index 96b2f0f9..f18bd8e9 100644 --- a/src/lib/js/components/controls/form/input.file.js +++ b/src/lib/js/components/controls/form/input.file.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class FileControl extends Control { diff --git a/src/lib/js/components/controls/form/input.hidden.js b/src/lib/js/components/controls/form/input.hidden.js index 18c33923..071d099b 100644 --- a/src/lib/js/components/controls/form/input.hidden.js +++ b/src/lib/js/components/controls/form/input.hidden.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class HiddenControl extends Control { diff --git a/src/lib/js/components/controls/form/input.number.js b/src/lib/js/components/controls/form/input.number.js index 555931a6..bfd3ba99 100644 --- a/src/lib/js/components/controls/form/input.number.js +++ b/src/lib/js/components/controls/form/input.number.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class NumberControl extends Control { diff --git a/src/lib/js/components/controls/form/input.text.js b/src/lib/js/components/controls/form/input.text.js index 3c7b30c4..72d9eaa3 100644 --- a/src/lib/js/components/controls/form/input.text.js +++ b/src/lib/js/components/controls/form/input.text.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' // import Components from '../..' diff --git a/src/lib/js/components/controls/form/radio-group.js b/src/lib/js/components/controls/form/radio-group.js index ec894f79..6c6b9575 100644 --- a/src/lib/js/components/controls/form/radio-group.js +++ b/src/lib/js/components/controls/form/radio-group.js @@ -1,5 +1,5 @@ import { generateOptionConfig } from './shared.js' -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class RadioGroupControl extends Control { diff --git a/src/lib/js/components/controls/form/select.js b/src/lib/js/components/controls/form/select.js index c03c56a5..f323ab0d 100644 --- a/src/lib/js/components/controls/form/select.js +++ b/src/lib/js/components/controls/form/select.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import { generateOptionConfig } from './shared.js' import Control from '../control.js' diff --git a/src/lib/js/components/controls/form/shared.js b/src/lib/js/components/controls/form/shared.js index 7bba0868..ca810ed6 100644 --- a/src/lib/js/components/controls/form/shared.js +++ b/src/lib/js/components/controls/form/shared.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import { toTitleCase } from '../../../common/utils/string.mjs' export const generateOptionConfig = (type, count = 3) => diff --git a/src/lib/js/components/controls/form/textarea.js b/src/lib/js/components/controls/form/textarea.js index 72e19e4a..ee5b5ce5 100644 --- a/src/lib/js/components/controls/form/textarea.js +++ b/src/lib/js/components/controls/form/textarea.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class TextAreaControl extends Control { diff --git a/src/lib/js/components/controls/html/header.js b/src/lib/js/components/controls/html/header.js index 5c5afb25..57ad4641 100644 --- a/src/lib/js/components/controls/html/header.js +++ b/src/lib/js/components/controls/html/header.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' const headerTags = Array.from(Array(5).keys()) diff --git a/src/lib/js/components/controls/html/hr.js b/src/lib/js/components/controls/html/hr.js index 9b59853b..04062cfd 100644 --- a/src/lib/js/components/controls/html/hr.js +++ b/src/lib/js/components/controls/html/hr.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class HRControl extends Control { diff --git a/src/lib/js/components/controls/html/paragraph.js b/src/lib/js/components/controls/html/paragraph.js index 3831e73d..4d210119 100644 --- a/src/lib/js/components/controls/html/paragraph.js +++ b/src/lib/js/components/controls/html/paragraph.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Control from '../control.js' class ParagraphControl extends Control { diff --git a/src/lib/js/components/controls/index.js b/src/lib/js/components/controls/index.js index accf2437..14ff2182 100644 --- a/src/lib/js/components/controls/index.js +++ b/src/lib/js/components/controls/index.js @@ -1,5 +1,5 @@ import Sortable from 'sortablejs' -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import actions from '../../common/actions.js' import { indexOfNode, orderObjectsBy } from '../../common/helpers.mjs' import events from '../../common/events.js' diff --git a/src/lib/js/components/fields/edit-panel-item.mjs b/src/lib/js/components/fields/edit-panel-item.mjs index f5b6a03b..c3013977 100644 --- a/src/lib/js/components/fields/edit-panel-item.mjs +++ b/src/lib/js/components/fields/edit-panel-item.mjs @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import { orderObjectsBy, indexOfNode } from '../../common/helpers.mjs' import dom from '../../common/dom.js' import animate from '../../common/animation.js' diff --git a/src/lib/js/components/fields/edit-panel.js b/src/lib/js/components/fields/edit-panel.js index 86911433..e5327326 100644 --- a/src/lib/js/components/fields/edit-panel.js +++ b/src/lib/js/components/fields/edit-panel.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import dom from '../../common/dom.js' import actions from '../../common/actions.js' import EditPanelItem from './edit-panel-item.mjs' diff --git a/src/lib/js/components/fields/field.js b/src/lib/js/components/fields/field.js index 1f8d9540..160a0645 100644 --- a/src/lib/js/components/fields/field.js +++ b/src/lib/js/components/fields/field.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import dom from '../../common/dom.js' import Panels from '../panels.js' import { clone, throttle, unique } from '../../common/utils/index.mjs' diff --git a/src/lib/js/components/panels.js b/src/lib/js/components/panels.js index 763926cc..2763d289 100644 --- a/src/lib/js/components/panels.js +++ b/src/lib/js/components/panels.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Sortable from 'sortablejs' import h, { indexOfNode } from '../common/helpers.mjs' import dom from '../common/dom.js' diff --git a/src/lib/js/components/rows/row.js b/src/lib/js/components/rows/row.js index 5009bd7f..ac93ad0a 100644 --- a/src/lib/js/components/rows/row.js +++ b/src/lib/js/components/rows/row.js @@ -1,4 +1,4 @@ -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import Sortable from 'sortablejs' import Component from '../component.js' import dom from '../../common/dom.js' diff --git a/src/lib/js/config.js b/src/lib/js/config.js index b15973da..011c66be 100644 --- a/src/lib/js/config.js +++ b/src/lib/js/config.js @@ -1,4 +1,4 @@ -import mi18n from 'mi18n' +import mi18n from '@draggable/i18n' import { isIE } from './common/helpers' const EN_US = import.meta.env.EN_US diff --git a/src/lib/js/editor.js b/src/lib/js/editor.js index 6e3643b7..49a7c1be 100644 --- a/src/lib/js/editor.js +++ b/src/lib/js/editor.js @@ -1,5 +1,5 @@ import '../sass/formeo.scss' -import i18n from 'mi18n' +import i18n from '@draggable/i18n' import dom from './common/dom.js' import Events from './common/events.js' import Actions from './common/actions.js' @@ -7,7 +7,7 @@ import Controls from './components/controls/index.js' import Components from './components/index.js' import { loadPolyfills, insertStyle, insertIcons, ajax } from './common/loaders.js' import { SESSION_LOCALE_KEY, FALLBACK_SVG_SPRITE } from './constants.js' -import { sessionStorage, merge } from './common/utils/index.mjs' +import { merge } from './common/utils/index.mjs' import { defaults } from './config.js' import sprite from '../icons/formeo-sprite.svg?raw' diff --git a/vite.config.js b/vite.config.js index b15a0af4..0ed2e016 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,16 +1,13 @@ import { resolve } from 'node:path' import { defineConfig } from 'vite' -import formeoI18n from 'formeo-i18n' -import { I18N } from 'mi18n' +import { languageFileOptions, enUS } from '@draggable/formeo-languages' import banner from 'vite-plugin-banner' import compression from 'vite-plugin-compression' -import { createHtmlPlugin } from 'vite-plugin-html' import { viteStaticCopy } from 'vite-plugin-static-copy' +import { createHtmlPlugin } from 'vite-plugin-html' import pkg from './package.json' -const { languageFiles, enUS } = formeoI18n - const bannerTemplate = ` /** ${pkg.name} - ${pkg.homepage} @@ -19,7 +16,14 @@ Author: ${pkg.author} */ ` -console.log(resolve('node_modules/formeo-i18n/dist/lang/')) +const isImage = extType => /png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType) +const getExtType = assetInfo => { + let [extType] = assetInfo.name.split('.').reverse() + if (isImage(extType)) { + extType = 'img' + } + return extType +} const sharedConfig = { server: { @@ -40,58 +44,46 @@ const sharedConfig = { }, } -const libConfig = { - ...sharedConfig, - build: { - emptyOutDir: false, - lib: { - entry: 'src/lib/js/index.js', - name: 'Formeo', - fileName: () => 'formeo.min.js', - formats: ['umd'], - outDir: resolve(__dirname, 'dist'), - }, - minify: 'terser', - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true, - }, - }, - }, - plugins: [ - banner(bannerTemplate), - compression({ - algorithm: 'gzip', - minRatio: 0.8, - ext: '.gz', - threshold: 10240, - }), - ], -} - -const demoConfig = { +export default defineConfig({ ...sharedConfig, root: 'src/demo', base: process.env.NODE_ENV === 'production' ? '/formeo/' : '/', resolve: { alias: { - 'formeo': resolve(__dirname, 'src/lib/js/index.js'), + formeo: resolve(__dirname, 'src/lib/js/index.js'), }, }, build: { - emptyOutDir: false, + emptyOutDir: true, rollupOptions: { input: { demo: resolve(__dirname, 'src/demo/index.html'), }, output: { - manualChunks:{ + manualChunks: { formeo: ['formeo'], }, + entryFileNames: 'assets/js/[name].min.js', + chunkFileNames: 'assets/js/[name].min.js', + assetFileNames: assetInfo => { + const extType = getExtType(assetInfo) + const ext = extType === 'img' ? '[ext]' : 'min.[ext]' + return `assets/${getExtType(assetInfo)}/[name].${ext}` + }, }, }, outDir: resolve(__dirname, 'dist/demo'), + minify: 'terser', + terserOptions: { + compress: { + drop_console: true, + drop_debugger: true, + }, + output: { + comments: false, + beautify: false, + }, + }, }, plugins: [ createHtmlPlugin({ @@ -101,32 +93,32 @@ const demoConfig = { filename: 'index.html', inject: { data: { - langFiles: Object.entries(languageFiles).map(([locale, val]) => { - const lang = I18N.processFile(val) - return { - locale, - dir: lang.dir, - nativeName: lang[locale], - } - }), + langFiles: languageFileOptions, version: pkg.version, }, }, }), + banner(bannerTemplate), + compression({ + algorithm: 'gzip', + minRatio: 0.8, + ext: '.gz', + threshold: 10240, + }), viteStaticCopy({ targets: [ { - src: resolve('node_modules/formeo-i18n/dist/lang/'), - dest: './src/demo/assets/lang/' - } - ] - }) + src: resolve('src/lib/icons/formeo-sprite.svg'), + dest: './assets/img/', + }, + { + src: resolve('node_modules', '@draggable/formeo-languages/dist/lang/*'), + dest: './assets/lang', + }, + ], + }), ], -} - -export default defineConfig(({ mode }) => { - if (mode === 'lib') { - return libConfig - } - return demoConfig + // optimizeDeps: { + // exclude: ['@draggable/i18n'] + // } }) diff --git a/vite.config.lib.mjs b/vite.config.lib.mjs new file mode 100644 index 00000000..f0ca6d32 --- /dev/null +++ b/vite.config.lib.mjs @@ -0,0 +1,50 @@ +import { defineConfig } from 'vite' +import banner from 'vite-plugin-banner' +import { resolve } from 'node:path' + +import pkg from './package.json' + +const bannerTemplate = ` +/** +${pkg.name} - ${pkg.homepage} +Version: ${pkg.version} +Author: ${pkg.author} +*/ +` + +export default defineConfig({ + root: './', + build: { + lib: { + entry: resolve(__dirname, 'src/lib/js/index.js'), + name: 'formeo', + fileName: format => `[name].${format}.js`, + formats: ['es', 'cjs', 'umd'], + }, + outDir: 'dist', + emptyOutDir: true, + minify: 'terser', + terserOptions: { + compress: { + drop_console: true, + drop_debugger: true, + }, + }, + rollupOptions: { + input: { + formeo: resolve(__dirname, 'src/lib/js/index.js'), + }, + output: { + assetFileNames: 'formeo.min.[ext]', + }, + }, + }, + plugins: [banner(bannerTemplate)], + css: { + preprocessorOptions: { + scss: { + api: 'modern-compiler', + }, + }, + }, +})