Skip to content

Instantly share code, notes, and snippets.

View mistyharsh's full-sized avatar
🎯
Focusing

Harshal mistyharsh

🎯
Focusing
View GitHub Profile
@mistyharsh
mistyharsh / webpack.config.js
Created February 18, 2024 10:24
medium-webpack-node-esm-only-01
const config = {
// Entry point and output
entry: './src/index.js',
output: {
path: process.cwd() + '/dist',
filename: 'output.js',
},
mode: 'production',
};
module.exports = {
entry: { /* config */ },
output: { /* config */ },
module: {
rules: [
// Regular css files
{
const sheet = new CSSStyleSheet();
// Replace all styles synchronously for this style sheet
sheet.replaceSync('p { color: green; }');
class FancyComponent1 extends HTMLElement {
constructor() {
super();
// Create style node outside of WebComponent
const style = document.createElement('style');
style.innerHTML = `
p { color: blue; }
`;
class FancyComponent extends HTMLElement {
constructor() {
class FancyComponent extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = `
<!-- Styles are scoped -->
<style>