Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implement rollup #2

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
yarn.lock
yarn-error.log
dist
lib
.DS_Store
28 changes: 23 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
"license": "BSD-3-Clause",
"description": "TeskaLabs ASAB WebUI Components Library",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"browserslist": [
"defaults"
],
"files": [
"dist"
"dist",
"dist/**/*.scss",
"dist/styles",
"dist/styles/**/*"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"build": "babel src --extensions '.js,.jsx' --out-dir dist && copyfiles -u 1 'src/**/*.{scss,jsx}' dist",
"prebuild": "babel src --out-dir lib --extensions '.js,.jsx' && cp -R src/**/*.scss lib/",
"build": "yarn prebuild && rollup -c && mkdir -p dist/styles && cp -R src/styles/**/* dist/styles/ && find src -name '*.scss' -exec cp {} dist/ \\;",
"clean": "rimraf dist"
},
"devDependencies": {
Expand All @@ -20,9 +28,19 @@
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-node-resolve": "^16.0.0",
"autoprefixer": "^10.4.20",
"babel-plugin-module-resolver": "^5.0.2",
"copyfiles": "^2.4.1",
"rimraf": "^5.0.0"
"postcss": "^8.5.1",
"rimraf": "^5.0.0",
"rollup": "^4.34.1",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"sass": "^1.83.4"
},
"peerDependencies": {
"@babel/runtime": "^7.22.11",
Expand Down
61 changes: 61 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import copy from "rollup-plugin-copy"; // Ensure SCSS files are copied

import { readFileSync } from "fs"; // Import FS to read package.json
import { fileURLToPath } from "url";
import path from "path";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(readFileSync(path.resolve(__dirname, "package.json"), "utf8"));

export default {
input: "lib/index.js",
output: [
{
file: "dist/index.cjs.js",
format: "cjs",
exports: "named",
sourcemap: true,
},
{
file: "dist/index.esm.js",
format: "esm",
exports: "named",
sourcemap: true,
},
],
plugins: [
peerDepsExternal(),
postcss({
extensions: [".css", ".scss"],
use: ["sass"],
extract: true,
minimize: true,
}),
resolve({
extensions: [".js", ".jsx", ".scss"],
}),
commonjs({
ignore: (id) => id.includes(".scss"),
}),
babel({
babelHelpers: "runtime",
extensions: [".js", ".jsx"],
exclude: /node_modules/,
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-transform-runtime"],
}),
copy({
targets: [
{ src: "src/styles/**/*", dest: "dist/styles" }, // Ensure SCSS files are copied
{ src: "src/**/*.scss", dest: "dist" }, // Copies all SCSS files to dist
],
flatten: false,
}),
],
external: [...Object.keys(packageJson.peerDependencies || {})],
};
8 changes: 5 additions & 3 deletions src/components/DateTime/useDateFNSLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import cs from 'date-fns/locale/cs'; // (possible exports: af, ar, arDZ, arEG, arMA, arSA, arTN, az, be, beTarask, bg, bn, bs, ca, cs, cy, da, de, deAT, el, enAU, enCA, enGB, enIE, enIN, enNZ, enUS, enZA, eo, es, et, eu, faIR, fi, fr, frCA, frCH, fy, gd, gl, gu, he, hi, hr, ht, hu, hy, id, is, it, itCH, ja, jaHira, ka, kk, km, kn, ko, lb, lt, lv, mk, mn, ms, mt, nb, nl, nlBE, nn, oc, pl, pt, ptBR, ro, ru, sk, sl, sq, sr, srLatn, sv, ta, te, th, tr, ug, uk, uz, uzCyrl, vi, zhCN, zhHK, zhTW)
// import cs from 'date-fns/locale/cs'; // (possible exports: af, ar, arDZ, arEG, arMA, arSA, arTN, az, be, beTarask, bg, bn, bs, ca, cs, cy, da, de, deAT, el, enAU, enCA, enGB, enIE, enIN, enNZ, enUS, enZA, eo, es, et, eu, faIR, fi, fr, frCA, frCH, fy, gd, gl, gu, he, hi, hr, ht, hu, hy, id, is, it, itCH, ja, jaHira, ka, kk, km, kn, ko, lb, lt, lv, mk, mn, ms, mt, nb, nl, nlBE, nn, oc, pl, pt, ptBR, ro, ru, sk, sl, sq, sr, srLatn, sv, ta, te, th, tr, ug, uk, uz, uzCyrl, vi, zhCN, zhHK, zhTW)

/*
To bundle the locales and avoid bundle size issues, we need to define the specific locales used.
Expand All @@ -20,14 +20,16 @@ import cs from 'date-fns/locale/cs'; // (possible exports: af, ar, arDZ, arEG, a
```
*/

const availableLocales = { cs };
// console.log("Loaded locale:", cs ? "OK" : "MISSING");

// const availableLocales = { cs };

const useDateFNSLocale = () => {
const language = useSelector((state) => state.language.current);
const [locale, setLocale] = useState(undefined);

useEffect(() => {
setLocale(availableLocales[language] || undefined);
setLocale(undefined);
}, [language]);

return locale;
Expand Down