From 186147d8ff782655a0a0ebdf62d13bbdc4eae69e Mon Sep 17 00:00:00 2001 From: Truong Nguyen Date: Sat, 16 Apr 2022 23:36:52 +0700 Subject: [PATCH 01/19] feat: (In Progress) Support SASS - Todo: Support @use, @import for SASS --- examples/vite-react/config/jest/setupTests.js | 2 +- .../config/jest/setupTestsBeforeEnv.js | 6 ++ examples/vite-react/jest.config.js | 3 +- examples/vite-react/package-lock.json | 81 +++++++++++++++++++ examples/vite-react/package.json | 1 + examples/vite-react/src/App.tsx | 6 +- examples/vite-react/src/assets/css/style.scss | 5 ++ examples/vite-react/src/global-style.scss | 5 ++ examples/vite-react/src/main.tsx | 1 + package-lock.json | 17 ++++ package.json | 1 + src/configure.ts | 48 +++++++++-- src/constants.ts | 2 + src/transform.ts | 28 +++++++ 14 files changed, 198 insertions(+), 8 deletions(-) create mode 100644 examples/vite-react/config/jest/setupTestsBeforeEnv.js create mode 100644 examples/vite-react/src/assets/css/style.scss create mode 100644 examples/vite-react/src/global-style.scss create mode 100644 src/constants.ts diff --git a/examples/vite-react/config/jest/setupTests.js b/examples/vite-react/config/jest/setupTests.js index 5c6233a3..27aad66f 100644 --- a/examples/vite-react/config/jest/setupTests.js +++ b/examples/vite-react/config/jest/setupTests.js @@ -2,7 +2,7 @@ import '@testing-library/jest-dom/extend-expect'; import { jestPreviewConfigure } from 'jest-preview'; jestPreviewConfigure({ - externalCss: ['src/index.css'], + externalCss: ['src/index.css', 'src/global-style.scss'], }); window.matchMedia = (query) => ({ diff --git a/examples/vite-react/config/jest/setupTestsBeforeEnv.js b/examples/vite-react/config/jest/setupTestsBeforeEnv.js new file mode 100644 index 00000000..650e87fd --- /dev/null +++ b/examples/vite-react/config/jest/setupTestsBeforeEnv.js @@ -0,0 +1,6 @@ +import { jestPreviewConfigure } from 'jest-preview'; + +jestPreviewConfigure({ + externalCss: ['src/index.css', 'src/global-style.scss'], + sassLoadPaths: ['src'], // Root for @use, @import +}); diff --git a/examples/vite-react/jest.config.js b/examples/vite-react/jest.config.js index dd4ddfe3..5a23724f 100644 --- a/examples/vite-react/jest.config.js +++ b/examples/vite-react/jest.config.js @@ -6,12 +6,13 @@ module.exports = { '!src/mocks/**', ], coveragePathIgnorePatterns: [], + setupFiles: ['./config/jest/setupTestsBeforeEnv.js'], setupFilesAfterEnv: ['./config/jest/setupTests.js'], testEnvironment: 'jsdom', modulePaths: ['/src'], transform: { '^.+\\.(ts|js|tsx|jsx)$': '@swc/jest', - '^.+\\.css$': 'jest-preview/transforms/css', + '^.+\\.(css|scss|sass)$': 'jest-preview/transforms/css', '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': 'jest-preview/transforms/file', }, diff --git a/examples/vite-react/package-lock.json b/examples/vite-react/package-lock.json index a8135d37..ce6ed1a1 100644 --- a/examples/vite-react/package-lock.json +++ b/examples/vite-react/package-lock.json @@ -1332,6 +1332,12 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1434,6 +1440,22 @@ "integrity": "sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==", "dev": true }, + "chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "ci-info": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.3.0.tgz", @@ -2125,6 +2147,15 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, "globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", @@ -2244,6 +2275,12 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "immutable": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.0.0.tgz", + "integrity": "sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw==", + "dev": true + }, "import-local": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.1.0.tgz", @@ -2308,6 +2345,15 @@ "has-bigints": "^1.0.1" } }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, "is-boolean-object": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", @@ -2342,6 +2388,12 @@ "has-tostringtag": "^1.0.0" } }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -2354,6 +2406,15 @@ "integrity": "sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==", "dev": true }, + "is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, "is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -9128,6 +9189,15 @@ "path-type": "^3.0.0" } }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "requires": { + "picomatch": "^2.2.1" + } + }, "redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -9212,6 +9282,17 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "sass": { + "version": "1.50.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.50.0.tgz", + "integrity": "sha512-cLsD6MEZ5URXHStxApajEh7gW189kkjn4Rc8DQweMyF+o5HF5nfEz8QYLMlPsTOD88DknatTmBWkOcw5/LnJLQ==", + "dev": true, + "requires": { + "chokidar": ">=3.0.0 <4.0.0", + "immutable": "^4.0.0", + "source-map-js": ">=0.6.2 <2.0.0" + } + }, "saxes": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz", diff --git a/examples/vite-react/package.json b/examples/vite-react/package.json index d205071b..69971af3 100644 --- a/examples/vite-react/package.json +++ b/examples/vite-react/package.json @@ -30,6 +30,7 @@ "jest-watch-typeahead": "^1.0.0", "npm-run-all": "^4.1.5", "prettier": "^2.6.0", + "sass": "^1.50.0", "typescript": "^4.5.4", "vite": "^2.8.0" } diff --git a/examples/vite-react/src/App.tsx b/examples/vite-react/src/App.tsx index 5c417ffb..a4a5367e 100644 --- a/examples/vite-react/src/App.tsx +++ b/examples/vite-react/src/App.tsx @@ -7,6 +7,7 @@ import logo2 from './assets/images/logo.svg'; import './App.css'; import './assets/css/App.css'; +import './assets/css/style.scss'; import styles from './style.module.css'; function App() { @@ -19,7 +20,10 @@ function App() {

Vite Example

This text is styled by styled-components

This text is styled by CSS Modules

- +

+ This text is styled by global configured SASS +

+

This text is styled by imported SASS