소스 검색

Improve LESS loading in Storybook (#5406)

GitOrigin-RevId: ad128b8be645ed54de498b543f655751a6a0799b
Alf Eaton 5 년 전
부모
커밋
4274782443
2개의 변경된 파일과 6개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 3
      services/web/.storybook/main.js
  2. 3 1
      services/web/.storybook/preview.js

+ 3 - 3
services/web/.storybook/main.js

@@ -1,4 +1,5 @@
 const path = require('path')
 const path = require('path')
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
 
 
 // NOTE: must be set before webpack config is imported
 // NOTE: must be set before webpack config is imported
 process.env.SHARELATEX_CONFIG = path.resolve(
 process.env.SHARELATEX_CONFIG = path.resolve(
@@ -22,8 +23,7 @@ module.exports = {
       ...storybookConfig.module.rules.filter(
       ...storybookConfig.module.rules.filter(
         rule => !rule.test.toString().includes('woff')
         rule => !rule.test.toString().includes('woff')
       ),
       ),
-      // Replace the less rule, adding to-string-loader
-      // Filter out the MiniCSS extraction, which conflicts with the built-in CSS loader
+      // Replace the LESS rule, and the CSS rule which conflicts with the built-in CSS loader
       ...customConfig.module.rules.filter(
       ...customConfig.module.rules.filter(
         rule =>
         rule =>
           !rule.test.toString().includes('less') &&
           !rule.test.toString().includes('less') &&
@@ -31,7 +31,7 @@ module.exports = {
       ),
       ),
       {
       {
         test: /\.less$/,
         test: /\.less$/,
-        use: ['to-string-loader', 'css-loader', 'less-loader'],
+        use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'],
       },
       },
     ]
     ]
 
 

+ 3 - 1
services/web/.storybook/preview.js

@@ -65,7 +65,9 @@ export const loaders = [
       // NOTE: this uses `${theme}style.less` rather than `${theme}.less`
       // NOTE: this uses `${theme}style.less` rather than `${theme}.less`
       // so that webpack only bundles files ending with "style.less"
       // so that webpack only bundles files ending with "style.less"
       activeStyle: await import(
       activeStyle: await import(
-        `../frontend/stylesheets/${theme === 'default-' ? '' : theme}style.less`
+        `!!to-string-loader!css-loader!less-loader!../frontend/stylesheets/${
+          theme === 'default-' ? '' : theme
+        }style.less`
       ),
       ),
     }
     }
   },
   },