简易的 less、css、style loader
// local-less-loader
const less = require("less");
module.exports = function (source) {
less.render(source, (e, output) => {
this.callback(e, output.css);
});
};
// local-css-loader
module.exports = function (source) {
// 有一些符号需要转一下
return JSON.stringify(source);
};
// local-style-loader
module.exports = function (source) {
const res = `
const e = document.createElement('style');
e.innerHTML = ${source};
document.head.appendChild(e)
`;
return res;
};
使用,
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ["local-style-loader", "local-css-loader"],
},
{
test: /\.less$/,
use: [
"local-style-loader",
"local-css-loader",
"local-postcss-loader",
"local-less-loader",
],
},
],
},
resolveLoader: {
modules: ["./node_modules", "./customedLoaders"],
},
};