Skip to content

Commit 0ae52bb

Browse files
committed
feat: css-module and scoped css in shadow dom
1 parent 8f5ce5a commit 0ae52bb

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

app-min/src/css.d.ts__if_typescript

Lines changed: 0 additions & 4 deletions
This file was deleted.

app-min/src/html.d.ts__if_typescript

Lines changed: 0 additions & 8 deletions
This file was deleted.

app-min/src/main.ext

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
import 'promise-polyfill/lib/polyfill';
33
import { DebugConfiguration } from '@aurelia/debug';
44
import { BasicConfiguration } from '@aurelia/jit-html-browser';
5+
// @if shadow-dom-open || shadow-dom-closed || css-module
6+
import { StyleConfiguration } from '@aurelia/runtime-html';
7+
// @endif
58
import { Aurelia } from '@aurelia/runtime';
6-
import { App } from './app';
9+
import { MyApp } from './my-app';
710

811
new Aurelia()
9-
.register(BasicConfiguration, DebugConfiguration)
12+
.register(
13+
BasicConfiguration,
14+
DebugConfiguration/* @if shadow-dom-open || shadow-dom-closed */,
15+
StyleConfiguration.shadowDOM()/* @endif *//* @if css-module */,
16+
StyleConfiguration.cssModulesProcessor()/* @endif */
17+
)
1018
.app({
11-
host: document.querySelector('app'),
12-
component: App
19+
host: document.querySelector('my-app'),
20+
component: MyApp
1321
})
1422
.start();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '*.html' {
2+
import { IBindableDescription } from '@aurelia/runtime';
3+
export const name: string;
4+
export const template: string;
5+
export default template;
6+
export const dependencies: string[];
7+
export const containerless: boolean | undefined;
8+
export const bindables: Record<string, IBindableDescription>;
9+
export const shadowOptions: { mode: 'open' | 'closed'} | undefined;
10+
export function getHTMLOnlyElement();
11+
}

dumber/gulpfile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function buildJs(src) {
101101

102102
return gulp.src(src, {sourcemaps: !isProduction, since: gulp.lastRun(build)})
103103
.pipe(gulpif(!isProduction, plumber()))
104-
.pipe(au2()) // inject aurelia conventions
104+
.pipe(au2())
105105
.pipe(transpile);
106106
}
107107

@@ -113,7 +113,10 @@ function buildHtml(src) {
113113
// @if shadow-dom-closed
114114
.pipe(au2({defaultShadowOptions: {mode: 'closed'}}));
115115
// @endif
116-
// @if !shadow-dom-open && !shadow-dom-closed
116+
// @if css-module
117+
.pipe(au2({useCSSModule: true}));
118+
// @endif
119+
// @if !shadow-dom-open && !shadow-dom-closed && !css-module
117120
.pipe(au2()); // inject aurelia conventions
118121
// @endif
119122
}

questions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ module.exports = [
2828
{value: 'shadow-dom-closed', title: 'ShadowDOM in closed mode', hint: "Closed mode means that you won't be able to access the shadow DOM from the outside."},
2929
]
3030
},
31+
{
32+
if: '!shadow-dom-open && !shadow-dom-closed',
33+
message: 'Do you want to use CSS Module?',
34+
choices: [
35+
{title: 'No'},
36+
{value: 'css-module', title: 'CSS Module is an alternative way to locally scope CSS class names. Do not use it together with ShadowDOM.'},
37+
]
38+
},
3139
{
3240
message: 'What transpiler would you like to use?',
3341
choices: [

webpack/webpack.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module.exports = function(env, { mode }) {
4141
// @if shadow-dom-closed
4242
{ test: /\.html$/i, use: { loader: '@aurelia/webpack-loader', options: { defaultShadowOptions: { mode: 'closed' } } }, exclude: /node_modules/ }
4343
// @endif
44-
// @if !shadow-dom-open && !shadow-dom-closed
44+
// @if css-module
45+
{ test: /\.html$/i, use: { loader: '@aurelia/webpack-loader', options: { useCSSModule: true } }, exclude: /node_modules/ }
46+
// @endif
47+
// @if !shadow-dom-open && !shadow-dom-closed && !css-module
4548
{ test: /\.html$/i, use: '@aurelia/webpack-loader', exclude: /node_modules/ }
4649
// @endif
4750
]

0 commit comments

Comments
 (0)