diff --git a/config/webpack.dev-stage.config.js b/config/webpack.dev-stage.config.js index e6c3f86e6..001ba145e 100644 --- a/config/webpack.dev-stage.config.js +++ b/config/webpack.dev-stage.config.js @@ -102,7 +102,7 @@ module.exports = merge(commonConfig, { ], // Silences compiler deprecation warnings. They mostly come from bootstrap and/or paragon. quietDeps: true, - silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin'], + silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin', 'legacy-js-api'], }, }, }, diff --git a/config/webpack.dev.config.js b/config/webpack.dev.config.js index c1376eb65..9dc4fea52 100644 --- a/config/webpack.dev.config.js +++ b/config/webpack.dev.config.js @@ -31,16 +31,18 @@ resolvePrivateEnvConfig('.env.private'); const aliases = getLocalAliases(); const PUBLIC_PATH = process.env.PUBLIC_PATH || '/'; -function getStyleUseConfig() { +function getStyleUseConfig({ isModule = false } = {}) { + const cssLoaderOptions = { + sourceMap: true, + ...(isModule + ? { modules: true } + : { modules: { compileType: 'icss' } } + ), + }; return [ { loader: 'css-loader', // translates CSS into CommonJS - options: { - sourceMap: true, - modules: { - compileType: 'icss', - }, - }, + options: cssLoaderOptions, }, { loader: 'postcss-loader', @@ -66,7 +68,7 @@ function getStyleUseConfig() { ], // Silences compiler deprecation warnings. They mostly come from bootstrap and/or paragon. quietDeps: true, - silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin'], + silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin', 'legacy-js-api'], }, }, }, @@ -118,6 +120,13 @@ module.exports = merge(commonConfig, { ...getStyleUseConfig(), ], }, + { + resource: /\.module\.(scss|css)$/, + use: [ + 'style-loader', // creates style nodes from JS strings + ...getStyleUseConfig({ isModule: true }), + ], + }, { use: [ 'style-loader', // creates style nodes from JS strings diff --git a/config/webpack.prod.config.js b/config/webpack.prod.config.js index 4c8079cc4..2f05591c0 100644 --- a/config/webpack.prod.config.js +++ b/config/webpack.prod.config.js @@ -133,7 +133,7 @@ module.exports = merge(commonConfig, { ], // Silences compiler deprecation warnings. They mostly come from bootstrap and/or paragon. quietDeps: true, - silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin'], + silenceDeprecations: ['abs-percent', 'color-functions', 'import', 'mixed-decls', 'global-builtin', 'legacy-js-api'], }, }, }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 5aed15f95..31b4ff91f 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -6,16 +6,40 @@ import appleUrl, { ReactComponent as Apple } from './apple.svg'; // @ts-ignore import appleImg from './apple.jpg'; -import './style.scss'; import ParagonPreview from './ParagonPreview'; +// Without CSS modules support +// @ts-ignore +import defaultStyles from './style.scss'; + +// With CSS modules support +// @ts-ignore +import moduleStyles from './example.module.scss'; + +// @ts-ignore +import exampleStyles from './example.scss'; + +console.log('defaultStyles', defaultStyles); +console.log('moduleStyles', moduleStyles); +console.log('exampleStyles', exampleStyles); + const App = () => { const newEnglandApples = ['macintosh', 'granny smith']; const allApples = [...newEnglandApples, 'fuji', 'golden delicious']; + + const stylesConfig = { + defaultStyles, + moduleStyles, + exampleStyles, + }; + return (

Test page

SCSS parsing tests

+
+        {JSON.stringify(stylesConfig, null, 2)}
+      

The Apples

("The Apples" should be red)

ES6 parsing tests

); diff --git a/example/src/example.module.scss b/example/src/example.module.scss new file mode 100644 index 000000000..541e7cec4 --- /dev/null +++ b/example/src/example.module.scss @@ -0,0 +1,14 @@ +$h3-color: red; + +h3 { + color: $h3-color; +} + +.text-align-right { + text-align: right; + color: blue; +} + +:export { + h3Color: $h3-color; +} diff --git a/example/src/example.scss b/example/src/example.scss new file mode 100644 index 000000000..dcf2b47ee --- /dev/null +++ b/example/src/example.scss @@ -0,0 +1,11 @@ +.text-align-right { + text-align: right; + color: blue; +} + +// .style-modified { +// .text-align-right { +// text-align: right; +// color: blue; +// } +// } diff --git a/example/src/index.jsx b/example/src/index.tsx similarity index 84% rename from example/src/index.jsx rename to example/src/index.tsx index a2ce6e1c2..258ac82f1 100644 --- a/example/src/index.jsx +++ b/example/src/index.tsx @@ -9,5 +9,7 @@ import App from './App'; global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr'); const rootContainer = document.getElementById('root'); -const root = createRoot(rootContainer); -root.render(); +if (rootContainer) { + const root = createRoot(rootContainer); + root.render(); +} diff --git a/example/src/style.scss b/example/src/style.scss index 529c6552c..f60b2124e 100644 --- a/example/src/style.scss +++ b/example/src/style.scss @@ -7,3 +7,7 @@ h3 { .text-align-right { text-align: right; } + +:export { + h3Color: $h3-color; +}