Skip to content

feat: add vite to bundle #740

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

Merged
merged 10 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ node_modules
.DS_Store
yarn-debug.log*
yarn-error.log*
.idea
.idea
dist
storybook-static
test-results
playwright-report
packages/strapi-icons/src
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"license": "MIT",
"private": true,
"scripts": {
"analyze:bundle": "lerna run analyze:bundle --stream",
"bootstrap": "lerna bootstrap",
"build-storybook": "lerna run build-storybook --stream",
"build": "lerna run build --stream --scope=@strapi/icons && lerna run build --stream --scope=@strapi/design-system",
"clean": "lerna clean",
"generate": "plop",
"lint-staged": "lerna run lint-staged --stream --",
"lint": "lerna run lint --stream",
Expand All @@ -27,13 +27,17 @@
},
"devDependencies": {
"@specifyapp/cli": "^0.0.51",
"@vitejs/plugin-react": "^2.2.0",
"chokidar-cli": "^3.0.0",
"cross-env": "^7.0.3",
"fs-extra": "^10.0.0",
"husky": "=4",
"lerna": "^4.0.0",
"lint-staged": ">=10",
"plop": "^2.7.4",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"tiny-glob": "^0.2.9",
"vite": "^3.2.2"
},
"husky": {
"hooks": {
Expand Down
32 changes: 32 additions & 0 deletions packages/strapi-design-system/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parserOptions": {
"ecmaVersion": 2020, // Allows for the parsing of modern ECMAScript features
"sourceType": "module", // Allows for the use of imports
"ecmaFeatures": {
"jsx": true // Allows for the parsing of JSX
}
},
"settings": {
"react": {
"version": "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
"extends": [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
"rules": {
"react/sort-prop-types": 1,
"default-case": "error",
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
},
"overrides": [
{
"files": "*.mdx",
"parser": "eslint-mdx",
"rules": {
"react/react-in-jsx-scope": "off"
}
}
]
}
32 changes: 0 additions & 32 deletions packages/strapi-design-system/.eslintrc.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/strapi-design-system/.gitignore

This file was deleted.

10 changes: 9 additions & 1 deletion packages/strapi-design-system/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
storybook-static
.DS_Store
src
src
codemod
.storybook
__mocks__
jest.config.js
playwright.config.js
test-bundler.js
vite.config.js
yarn.lock
7 changes: 7 additions & 0 deletions packages/strapi-design-system/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
7 changes: 0 additions & 7 deletions packages/strapi-design-system/.prettierrc.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/strapi-design-system/babel.config.js

This file was deleted.

34 changes: 0 additions & 34 deletions packages/strapi-design-system/createIndexFiles.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/strapi-design-system/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module.exports = {
export default {
testRegex: ['src/.*\\.spec\\.(jsx|js)$', 'tests/.*\\.spec.js$'],
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect', './test-bundler.js'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
'^@strapi/icons/(.*)': '<rootDir>/../strapi-icons/dist/$1',
'^@strapi/icons': '<rootDir>/../strapi-icons/dist/index.js',
},
testEnvironment: 'jsdom',
transform: {
Expand Down
41 changes: 22 additions & 19 deletions packages/strapi-design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"name": "@strapi/design-system",
"version": "1.2.5",
"main": "index.js",
"license": "MIT",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./*": "./dist/*"
},
"sideEffects": false,
"dependencies": {
"@floating-ui/react-dom": "^1.0.0",
"@internationalized/number": "^3.1.1",
"compute-scroll-into-view": "^1.0.17",
"prop-types": "^15.7.2"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/plugin-transform-runtime": "^7.13.2",
"@babel/preset-env": "^7.13.0",
"@babel/preset-react": "^7.12.13",
"@figspec/react": "^0.1.5",
"@juggle/resize-observer": "^3.4.0",
"@playwright/test": "1.27.1",
Expand All @@ -23,11 +29,10 @@
"@storybook/react": "^6.5.13",
"@swc/core": "^1.3.11",
"@swc/jest": "^0.2.23",
"@strapi/icons": "*",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^11.2.5",
"axe-playwright": "^1.1.11",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"cross-env": "^7.0.3",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
Expand All @@ -38,17 +43,14 @@
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.2.2",
"jest-styled-components": "^7.1.1",
"prettier": "^2.2.1",
"prettier": "^2.7.1",
"qs": "^6.10.3",
"react": "^17.0.1",
"react-copy-to-clipboard": "^5.0.4",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"storybook-dark-mode": "^1.1.2",
"styled-components": "^5.3.6",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^4.5.0",
"url-loader": "^4.1.1"
"styled-components": "^5.3.6"
},
"peerDependencies": {
"@strapi/icons": "^1.2.4",
Expand All @@ -57,15 +59,16 @@
"react-router-dom": "^5.2.0",
"styled-components": "^5.2.1"
},
"peerDependenciesMeta": {
"react-router-dom": {
"optional": true
}
},
"scripts": {
"analyze:bundle": "cross-env BUNDLE_ANALYZE=1 webpack",
"dev": "vite",
"prebuild": "rimraf dist",
"build": "yarn build:files && cross-env IS_V2=true yarn build:files",
"build:files": "yarn build:dev && yarn build:prod && yarn copy:files && yarn create:index-files",
"build:dev": "cross-env NODE_ENV=development webpack-cli",
"build:prod": "cross-env NODE_ENV=production webpack-cli",
"copy:files": "node ../../tools/copy-files.js",
"create:index-files": "node ./createIndexFiles.js",
"build": "yarn build:prod",
"build:prod": "vite build",
"build-storybook": "build-storybook",
"lint": "eslint . --ext .js,.jsx,.mdx --fix",
"lint-staged": "eslint --fix",
Expand Down
6 changes: 2 additions & 4 deletions packages/strapi-design-system/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { devices } = require('@playwright/test');
import { devices } from '@playwright/test';

const config = {
export default {
testMatch: '**/__tests__/*.e2e.js',
// Forbid test.only on CI
forbidOnly: !!process.env.CI,
Expand Down Expand Up @@ -35,5 +35,3 @@ const config = {
},
],
};

module.exports = config;
5 changes: 5 additions & 0 deletions packages/strapi-design-system/src/Portal/Portal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLayoutEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';

export const Portal = ({ children }) => {
const rootRef = useRef(null);
Expand All @@ -23,3 +24,7 @@ export const Portal = ({ children }) => {

return createPortal(children, rootRef.current);
};

Portal.propTypes = {
children: PropTypes.node.isRequired,
};
36 changes: 36 additions & 0 deletions packages/strapi-design-system/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { resolve } from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import glob from 'tiny-glob';

export default glob('./src/**/!(*.spec|*.e2e).{js,svg}').then(async (paths) => {
console.log(paths, resolve(__dirname, './src/index.js'));
return defineConfig({
esbuild: {
loader: 'jsx',
include: /src\/.*\.jsx?$/,
exclude: [],
},
build: {
target: 'es2020',
lib: {
entry: {},
formats: ['cjs', 'es'],
fileName: (format) => {
return `[name].${format === 'es' ? 'js' : format}`;
},
},
rollupOptions: {
input: [resolve(__dirname, './src/index.js'), ...paths.map((path) => `./${path}`)],
// make sure to externalize deps that shouldn't be bundled
// into your library
external: (id) => !id.startsWith('.') && !id.startsWith('/'),
output: {
dir: 'dist',
preserveModules: true,
},
},
},
plugins: [react()],
});
});
Loading