Skip to content

Commit 3bdacb3

Browse files
committed
chore: add example 🍭
1 parent 7fd8b7a commit 3bdacb3

File tree

9 files changed

+591
-0
lines changed

9 files changed

+591
-0
lines changed

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist
2+
/node_modules

example/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "example",
3+
"private": true,
4+
"scripts": {
5+
"build": "webpack --mode production"
6+
},
7+
"devDependencies": {
8+
"lightningcss-loader": "file:../",
9+
"webpack": "^5.97.1",
10+
"webpack-cli": "^6.0.1"
11+
},
12+
"browserslist": [
13+
"chrome 40",
14+
"ie 10"
15+
]
16+
}

example/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './styles/index.css'
2+
import './styles/duplicate.css'
3+
4+
console.log(1)

example/src/styles/duplicate.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "./media.css";
2+
3+
body {
4+
content: "duplicate";
5+
}

example/src/styles/index.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import './media.css';
2+
3+
body {
4+
display: flex;
5+
background-color: #ffffffff;
6+
}
7+
8+
@media (--small) {
9+
body {
10+
width: 10px;
11+
}
12+
}

example/src/styles/media.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@custom-media --small (max-width: 600px);
2+
3+
html {
4+
transition: all .1s;
5+
6+
& .nested {
7+
color: red;
8+
}
9+
}

example/webpack.config.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const path = require('path')
2+
const lightningcssImpl = require('lightningcss')
3+
4+
const LightningCssLoader = path.join(__dirname, '../dist/index.js')
5+
const LightningCssLoaderMod = require(LightningCssLoader)
6+
const LightningCssMinifyPlugin = LightningCssLoaderMod.LightningCssMinifyPlugin
7+
8+
// for features testing
9+
const disableNesting = false
10+
11+
// for custom-media
12+
const enableCustomMedia = true
13+
14+
/** @type {import('../dist/interface').IMinifyPluginOpts} */
15+
const minifyOpts = {
16+
features: {
17+
exclude: lightningcssImpl.Features.Nesting,
18+
},
19+
}
20+
21+
module.exports = {
22+
entry: './src/index.js',
23+
output: {
24+
filename: 'bundle.js',
25+
},
26+
experiments: {
27+
css: true,
28+
},
29+
module: {
30+
rules: [
31+
{
32+
test: /\.css$/,
33+
use: [
34+
{
35+
loader: path.join(__dirname, '../dist/index.js'),
36+
options: {
37+
drafts: {
38+
customMedia: enableCustomMedia,
39+
},
40+
implementation: lightningcssImpl,
41+
42+
// for disabling features
43+
...(disableNesting
44+
? {
45+
...minifyOpts.features,
46+
}
47+
: {}),
48+
},
49+
},
50+
],
51+
},
52+
],
53+
},
54+
plugins: [new LightningCssMinifyPlugin(disableNesting ? minifyOpts : {})],
55+
}

pnpm-lock.yaml

Lines changed: 485 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages:
2+
- ./
3+
- ./example

0 commit comments

Comments
 (0)