Skip to content

Commit 4dad151

Browse files
committedDec 13, 2019
feat: basic style support
1 parent 3aa5058 commit 4dad151

File tree

6 files changed

+95
-12
lines changed

6 files changed

+95
-12
lines changed
 

‎example/App.vue

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<template>
2-
<img src="./logo.png">
2+
<img class="logo" src="./logo.png">
3+
<Button>slotttt</Button>
34
<Button>slot content</Button>
45
<Button>slot content</Button>
5-
<Button>slot content</Button>
6-
<div class="hmmmmm">
7-
<span>fsefesfsefsef</span>
8-
</div>
96
</template>
107

11-
128
<script>
139
import Button from './Button.vue'
1410
@@ -18,3 +14,10 @@ export default {
1814
}
1915
}
2016
</script>
17+
18+
<style>
19+
.logo {
20+
width: 100px;
21+
border: 1px solid red;
22+
}
23+
</style>

‎example/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
<link rel="stylesheet" href="/dist/main.css">
12
<div id="app"></div>
23
<script src="/dist/bundle.js"></script>

‎example/webpack.config.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path')
22
const VueLoaderPlugin = require('../dist/plugin')
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
34

45
module.exports = {
56
mode: 'development',
@@ -33,6 +34,18 @@ module.exports = {
3334
}
3435
}
3536
]
37+
},
38+
{
39+
test: /\.css$/,
40+
use: [
41+
{
42+
loader: MiniCssExtractPlugin.loader,
43+
options: {
44+
hmr: process.env.NODE_ENV !== 'production'
45+
}
46+
},
47+
'css-loader'
48+
]
3649
}
3750
]
3851
},
@@ -47,6 +60,9 @@ module.exports = {
4760
}
4861
},
4962
plugins: [
50-
new VueLoaderPlugin()
63+
new VueLoaderPlugin(),
64+
new MiniCssExtractPlugin({
65+
filename: '[name].css'
66+
})
5167
]
5268
}

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dev": "tsc --watch",
1313
"build": "tsc",
1414
"dev-example": "webpack-dev-server --config example/webpack.config.js --inline --hot",
15-
"build-example": "webpack --config example/webpack.config.js --mode=production"
15+
"build-example": "webpack --config example/webpack.config.js --mode=production --devtool=source-map"
1616
},
1717
"peerDependencies": {
1818
"@vue/compiler-sfc": "^3.0.0-alpha.0"
@@ -29,6 +29,7 @@
2929
"@types/webpack": "^4.41.0",
3030
"css-loader": "^3.3.2",
3131
"file-loader": "^5.0.2",
32+
"mini-css-extract-plugin": "^0.8.0",
3233
"typescript": "^3.7.3",
3334
"url-loader": "^3.0.0",
3435
"webpack": "^4.41.2",

‎src/index.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
TemplateCompiler,
99
CompilerOptions,
1010
SFCBlock,
11-
SFCTemplateCompileOptions
11+
SFCTemplateCompileOptions,
12+
SFCStyleBlock
1213
} from '@vue/compiler-sfc'
1314
import { selectBlock } from './select'
1415
import { genHotReloadCode } from './hotReload'
@@ -134,7 +135,18 @@ const loader: webpack.loader.Loader = function(source) {
134135
// styles
135136
let stylesCode = ``
136137
if (descriptor.styles.length) {
137-
// TODO handle style
138+
descriptor.styles.forEach((style: SFCStyleBlock, i: number) => {
139+
const src = style.src || resourcePath
140+
const attrsQuery = attrsToQuery(style.attrs, 'css')
141+
const inheritQuery = `&${loaderContext.resourceQuery.slice(1)}`
142+
// make sure to only pass id when necessary so that we don't inject
143+
// duplicate tags when multiple components import the same css file
144+
const idQuery = style.scoped ? `&id=${id}` : ``
145+
const query = `?vue&type=style&index=${i}${idQuery}${attrsQuery}${inheritQuery}`
146+
const styleRequest = stringifyRequest(src + query)
147+
// TODO CSS Modules & SSR
148+
stylesCode += `import ${styleRequest}`
149+
})
138150
}
139151

140152
let code = [

‎yarn.lock

+52-2
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,11 @@ is-path-inside@^2.1.0:
21092109
dependencies:
21102110
path-is-inside "^1.0.2"
21112111

2112+
is-plain-obj@^1.0.0:
2113+
version "1.1.0"
2114+
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
2115+
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
2116+
21122117
is-plain-object@^2.0.3, is-plain-object@^2.0.4:
21132118
version "2.0.4"
21142119
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
@@ -2223,7 +2228,7 @@ loader-runner@^2.4.0:
22232228
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
22242229
integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw==
22252230

2226-
loader-utils@1.2.3, loader-utils@^1.2.3:
2231+
loader-utils@1.2.3, loader-utils@^1.1.0, loader-utils@^1.2.3:
22272232
version "1.2.3"
22282233
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.2.3.tgz#1ff5dc6911c9f0a062531a4c04b609406108c2c7"
22292234
integrity sha512-fkpz8ejdnEMG3s37wGL07iSBDg99O9D5yflE9RGNH3hRdx9SOwYfnGYdZOUIZitN8E+E2vkq3MUMYMvPYl5ZZA==
@@ -2392,6 +2397,16 @@ mimic-fn@^2.0.0:
23922397
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
23932398
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
23942399

2400+
mini-css-extract-plugin@^0.8.0:
2401+
version "0.8.0"
2402+
resolved "https://registry.yarnpkg.com/mini-css-extract-plugin/-/mini-css-extract-plugin-0.8.0.tgz#81d41ec4fe58c713a96ad7c723cdb2d0bd4d70e1"
2403+
integrity sha512-MNpRGbNA52q6U92i0qbVpQNsgk7LExy41MdAlG84FeytfDOtRIf/mCHdEgG8rpTKOaNKiqUnZdlptF469hxqOw==
2404+
dependencies:
2405+
loader-utils "^1.1.0"
2406+
normalize-url "1.9.1"
2407+
schema-utils "^1.0.0"
2408+
webpack-sources "^1.1.0"
2409+
23952410
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
23962411
version "1.0.1"
23972412
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
@@ -2621,6 +2636,16 @@ normalize-path@^3.0.0:
26212636
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
26222637
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
26232638

2639+
normalize-url@1.9.1:
2640+
version "1.9.1"
2641+
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-1.9.1.tgz#2cc0d66b31ea23036458436e3620d85954c66c3c"
2642+
integrity sha1-LMDWazHqIwNkWENuNiDYWVTGbDw=
2643+
dependencies:
2644+
object-assign "^4.0.1"
2645+
prepend-http "^1.0.0"
2646+
query-string "^4.1.0"
2647+
sort-keys "^1.0.0"
2648+
26242649
npm-bundled@^1.0.1:
26252650
version "1.1.1"
26262651
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.1.1.tgz#1edd570865a94cdb1bc8220775e29466c9fb234b"
@@ -3003,6 +3028,11 @@ postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.23, postcss@^7.0.5, postcss@^7.0.
30033028
source-map "^0.6.1"
30043029
supports-color "^6.1.0"
30053030

3031+
prepend-http@^1.0.0:
3032+
version "1.0.4"
3033+
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
3034+
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
3035+
30063036
process-nextick-args@~2.0.0:
30073037
version "2.0.1"
30083038
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
@@ -3088,6 +3118,14 @@ qs@6.7.0:
30883118
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
30893119
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
30903120

3121+
query-string@^4.1.0:
3122+
version "4.3.4"
3123+
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
3124+
integrity sha1-u7aTucqRXCMlFbIosaArYJBD2+s=
3125+
dependencies:
3126+
object-assign "^4.1.0"
3127+
strict-uri-encode "^1.0.0"
3128+
30913129
querystring-es3@^0.2.0:
30923130
version "0.2.1"
30933131
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@@ -3499,6 +3537,13 @@ sockjs@0.3.19:
34993537
faye-websocket "^0.10.0"
35003538
uuid "^3.0.1"
35013539

3540+
sort-keys@^1.0.0:
3541+
version "1.1.2"
3542+
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-1.1.2.tgz#441b6d4d346798f1b4e49e8920adfba0e543f9ad"
3543+
integrity sha1-RBttTTRnmPG05J6JIK37oOVD+a0=
3544+
dependencies:
3545+
is-plain-obj "^1.0.0"
3546+
35023547
source-list-map@^2.0.0:
35033548
version "2.0.1"
35043549
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
@@ -3620,6 +3665,11 @@ stream-shift@^1.0.0:
36203665
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
36213666
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
36223667

3668+
strict-uri-encode@^1.0.0:
3669+
version "1.1.0"
3670+
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
3671+
integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
3672+
36233673
string-width@^1.0.1:
36243674
version "1.0.2"
36253675
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
@@ -4061,7 +4111,7 @@ webpack-log@^2.0.0:
40614111
ansi-colors "^3.0.0"
40624112
uuid "^3.3.2"
40634113

4064-
webpack-sources@^1.4.0, webpack-sources@^1.4.1:
4114+
webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1:
40654115
version "1.4.3"
40664116
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
40674117
integrity sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==

0 commit comments

Comments
 (0)
Please sign in to comment.