Skip to content

Commit 5ffd69d

Browse files
committed
Add linaria to svelte-webpack
1 parent 0b482db commit 5ffd69d

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

svelte-webpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"devDependencies": {
55
"cross-env": "^5.2.0",
66
"css-loader": "^2.1.1",
7+
"linaria": "^1.3.3",
78
"mini-css-extract-plugin": "^0.6.0",
89
"serve": "^11.0.0",
910
"style-loader": "^0.23.1",

svelte-webpack/src/App.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
<script>
2+
import { css } from 'linaria';
3+
import { externalStyle } from './styles.js';
4+
25
export let name;
6+
7+
const localStyle = css`
8+
color: green;
9+
`;
310
</script>
411

512
<style>
613
h1 {
714
color: purple;
815
}
16+
code {
17+
font-size: 16px;
18+
}
919
</style>
1020

11-
<h1>Hello {name}!</h1>
21+
<h1>Hello {name}!</h1>
22+
<p class={localStyle}>This is styled with Linaria styles in a <code>.svelte</code> file</p>
23+
<p class={externalStyle}>This is using Linaria styles imported from a <code>.js</code> file!</p>

svelte-webpack/src/styles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { css } from 'linaria';
2+
3+
export const externalStyle = css`
4+
font-style: italic;
5+
`;

svelte-webpack/webpack.config.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const path = require('path');
44
const mode = process.env.NODE_ENV || 'development';
55
const prod = mode === 'production';
66

7+
const linariaLoader = {
8+
loader: 'linaria/loader',
9+
options: {
10+
sourceMap: !prod,
11+
cacheDirectory: path.resolve(__dirname, 'node_modules/.cache/.linaria-cache')
12+
}
13+
};
14+
715
module.exports = {
816
entry: {
917
bundle: ['./src/main.js']
@@ -22,15 +30,24 @@ module.exports = {
2230
},
2331
module: {
2432
rules: [
33+
{
34+
test: /\.m?js$/,
35+
exclude: /node_modules/,
36+
use: [linariaLoader]
37+
},
2538
{
2639
test: /\.svelte$/,
27-
use: {
28-
loader: 'svelte-loader',
29-
options: {
30-
emitCss: true,
31-
hotReload: true
32-
}
33-
}
40+
use: [
41+
linariaLoader,
42+
{
43+
loader: 'svelte-loader',
44+
options: {
45+
dev: !prod,
46+
emitCss: true,
47+
hotReload: true
48+
},
49+
},
50+
],
3451
},
3552
{
3653
test: /\.css$/,

0 commit comments

Comments
 (0)