场景:
比如 html中有些内联样式和外联样式,如何让打包后的外联样式,在内联样式上面呢 避免内联样式被覆盖
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
options: {}
},
'css-loader'
]
}
已解决
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
options: {
insert: function insertAtTop(element) {
var parent = document.querySelector('head');
var lastInsertedElement = window._lastElementInsertedByStyleLoader;
console.log('lastInsertedElement', lastInsertedElement);
if (!lastInsertedElement) {
parent.insertBefore(element, parent.firstChild);
} else if (lastInsertedElement.nextSibling) {
parent.insertBefore(element, lastInsertedElement.nextSibling);
} else {
parent.appendChild(element);
}
window._lastElementInsertedByStyleLoader = element;
}
}
},
'css-loader'
]
}
正文完