Skip to content

Commit 134e295

Browse files
committed
Enhance webpack configuration to support both .less and .css files for gradual migration to native CSS. Update entry file discovery and add rules for processing CSS files.
1 parent 50c4ad5 commit 134e295

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

webpack.config.css.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
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
*/
56
const path = require('path');
67
const glob = require('glob');
78
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
89
const LessPluginCleanCss = require('less-plugin-clean-css');
910
const 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
1213
const lessFiles = glob.sync('./static/css/page-*.less');
14+
const cssFiles = glob.sync('./static/css/page-*.css');
1315
const entries = {};
16+
1417
lessFiles.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+
2030
module.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: /\.less$/,
3344
use: [
@@ -55,6 +66,20 @@ module.exports = {
5566
}
5667
}
5768
]
69+
},
70+
// Rule for .css files (native CSS)
71+
{
72+
test: /\.css$/,
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

Comments
 (0)