11/* eslint-env node, es6 */
22/*
3- * Webpack config for compiling Less files to independent CSS files in static/build/
3+ * Webpack config for compiling Less and CSS files to independent CSS files in static/build/
4+ * Supports both .less and .css entry points for gradual migration from LESS to native CSS.
45 */
56const path = require ( 'path' ) ;
67const glob = require ( 'glob' ) ;
78const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
89const LessPluginCleanCss = require ( 'less-plugin-clean-css' ) ;
910const distDir = path . resolve ( __dirname , process . env . BUILD_DIR || 'static/build/css' ) ;
1011
11- // Find all Less files matching static/css/page-*.less
12+ // Find all entry files matching static/css/page-*.less or static/css/page-*.css
1213const lessFiles = glob . sync ( './static/css/page-*.less' ) ;
14+ const cssFiles = glob . sync ( './static/css/page-*.css' ) ;
1315const entries = { } ;
16+
1417lessFiles . forEach ( file => {
1518 // e.g. page-home.less -> page-home
1619 const name = path . basename ( file , '.less' ) ;
1720 entries [ name ] = file ;
1821} ) ;
1922
23+ cssFiles . forEach ( file => {
24+ // e.g. page-home.css -> page-home
25+ // CSS files take precedence if both .less and .css exist (migration complete)
26+ const name = path . basename ( file , '.css' ) ;
27+ entries [ name ] = file ;
28+ } ) ;
29+
2030module . exports = {
2131 context : __dirname ,
2232 entry : entries ,
@@ -28,6 +38,7 @@ module.exports = {
2838 } ,
2939 module : {
3040 rules : [
41+ // Rule for .less files (legacy, to be removed after migration)
3142 {
3243 test : / \. l e s s $ / ,
3344 use : [
@@ -55,6 +66,20 @@ module.exports = {
5566 }
5667 }
5768 ]
69+ } ,
70+ // Rule for .css files (native CSS)
71+ {
72+ test : / \. c s s $ / ,
73+ use : [
74+ MiniCssExtractPlugin . loader ,
75+ {
76+ loader : 'css-loader' ,
77+ options : {
78+ url : false ,
79+ import : true // Enable @import resolution
80+ }
81+ }
82+ ]
5883 }
5984 ]
6085 } ,
0 commit comments