Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active January 1, 2021 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/0d67626f3efcfe81072d81d67133d822 to your computer and use it in GitHub Desktop.
Save YonatanKra/0d67626f3efcfe81072d81d67133d822 to your computer and use it in GitHub Desktop.
Working raw-loader for CSS
import style from "./app.element.css";
import template from "./app.element.html";
export class AppElement extends HTMLElement {
public static observedAttributes = [];
connectedCallback() {
const title = 'custom-webpack';
this.attachShadow({mode: 'open'});
this.shadowRoot.innerHTML = `<style>${style}</style>` + template.replace('${title}', title);
}
}
customElements.define('custom-webpack-root', AppElement);
module.exports = (config, context) => {
return {
...config,
module: {
...config.module,
rules: [
config.module.rules[0],
{
test: /\.html$/i,
use: 'raw-loader',
},
{
test: /\.css$/i,
use: 'raw-loader',
},
],
},
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment