mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 16:33:15 +01:00
enable css modules
This commit is contained in:
parent
e5ebf85c9c
commit
9353240d89
2 changed files with 43 additions and 1 deletions
34
build/cssScoopeGenerator.js
Normal file
34
build/cssScoopeGenerator.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = function() {
|
||||||
|
const index = {};
|
||||||
|
const componentNames = {};
|
||||||
|
|
||||||
|
return function (localName, resourcePath) {
|
||||||
|
let id = index[resourcePath];
|
||||||
|
if (id === undefined) {
|
||||||
|
id = getComponentName(resourcePath);
|
||||||
|
index[resourcePath] = id;
|
||||||
|
}
|
||||||
|
if (localName === 'root') {
|
||||||
|
localName = '';
|
||||||
|
} else {
|
||||||
|
localName = '-' + localName
|
||||||
|
}
|
||||||
|
return 'x-' + id + localName;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getComponentName(resourcePath) {
|
||||||
|
let filename = path.basename(resourcePath);
|
||||||
|
let name = path.parse(filename).name;
|
||||||
|
let suffix = '';
|
||||||
|
let collisionCounter = 0;
|
||||||
|
while (componentNames[name + suffix] !== undefined) {
|
||||||
|
suffix = collisionCounter ++;
|
||||||
|
}
|
||||||
|
name = name + suffix;
|
||||||
|
componentNames[name] = true;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
const generateCSSScopedName = require('./build/cssScoopeGenerator')();
|
||||||
|
|
||||||
const WEB_APP = path.join(__dirname, 'web/app');
|
const WEB_APP = path.join(__dirname, 'web/app');
|
||||||
const MODULES = path.join(__dirname, 'modules');
|
const MODULES = path.join(__dirname, 'modules');
|
||||||
|
|
@ -43,7 +44,14 @@ module.exports = {
|
||||||
test: /\.less$/,
|
test: /\.less$/,
|
||||||
use: [
|
use: [
|
||||||
'style-loader',
|
'style-loader',
|
||||||
'css-loader?-url',
|
{
|
||||||
|
loader: 'css-loader',
|
||||||
|
options: {
|
||||||
|
getLocalIdent: (context, localIdentName, localName) => generateCSSScopedName(localName, context.resourcePath),
|
||||||
|
modules: true,
|
||||||
|
url: false
|
||||||
|
}
|
||||||
|
},
|
||||||
'less-loader'
|
'less-loader'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue