質問編集履歴

3

わかったことがあったので質問文を修正しました

2018/11/06 08:35

投稿

sugishio
sugishio

スコア47

test CHANGED
File without changes
test CHANGED
@@ -2,9 +2,15 @@
2
2
 
3
3
  こちらを参考に`.vue`ファイル内のcssを外部ファイルに抽出したのですが、
4
4
 
5
- まだ一部のファイルがhtml埋め込まれた状態で書き出されていまいます。
5
+ vueコンポーネント内に記述したスタイルは`[name].css`内に書き出されておらず、
6
6
 
7
+ そのページでマウントされるコンポーネントのcssがjsによって追加されているようです。
8
+
9
+
10
+
7
- ありうる原因とて、何がありますでしょうか。。
11
+ - これはvue-loaderの正い挙動なのでしょうか
12
+
13
+ - `[name].css`内に書き出すにはどうしたら良いのでしょうか?
8
14
 
9
15
 
10
16
 
@@ -99,639 +105,3 @@
99
105
  }
100
106
 
101
107
  ```
102
-
103
-
104
-
105
- ## headタグ内に埋め込まれたままのcss(scss)
106
-
107
-
108
-
109
- ```scss
110
-
111
- .loading {
112
-
113
- display: flex;
114
-
115
- justify-content: center;
116
-
117
- align-items: center;
118
-
119
- width: 100%;
120
-
121
- height: 300px;
122
-
123
- img {
124
-
125
- width: 40px;
126
-
127
- height: 40px;
128
-
129
- }
130
-
131
- }
132
-
133
- .fade-enter-active, .fade-leave-active {
134
-
135
- transition: all 1s ease;
136
-
137
- }
138
-
139
- .fade-enter, .fade-leave-to {
140
-
141
- opacity: 0;
142
-
143
- }
144
-
145
- ```
146
-
147
-
148
-
149
- ```scss
150
-
151
- @import 'mixins';
152
-
153
-
154
-
155
- .weather {
156
-
157
- @extend %link-overlay;
158
-
159
- display: block;
160
-
161
- height: 50vw;
162
-
163
- max-height: 460px;
164
-
165
- background-image: url('/images/common/weather/bg/cloudy_sp.png');
166
-
167
- background-position: center center;
168
-
169
- background-size: cover;
170
-
171
- color: inherit;
172
-
173
-
174
-
175
- &.sunny {
176
-
177
- background-image: url('/images/common/weather/bg/sunny_sp.png');
178
-
179
- }
180
-
181
-
182
-
183
- &.rainy1 {
184
-
185
- background-image: url('/images/common/weather/bg/rainy1_sp.png');
186
-
187
- }
188
-
189
-
190
-
191
- &.rainy2 {
192
-
193
- background-image: url('/images/common/weather/bg/rainy2_sp.png');
194
-
195
- }
196
-
197
-
198
-
199
- &.snowy1 {
200
-
201
- background-image: url('/images/common/weather/bg/snowy1_sp.png');
202
-
203
- }
204
-
205
-
206
-
207
- &.snowy2 {
208
-
209
- background-image: url('/images/common/weather/bg/snowy2_sp.png');
210
-
211
- }
212
-
213
-
214
-
215
- &__container {
216
-
217
- display: flex;
218
-
219
- flex-direction: column;
220
-
221
- justify-content: space-between;
222
-
223
- height: 100%;
224
-
225
- padding: 1.5rem;
226
-
227
- flex-wrap: wrap;
228
-
229
- }
230
-
231
-
232
-
233
- &__area {
234
-
235
- font-size: 1.2rem;
236
-
237
- }
238
-
239
-
240
-
241
- &__date {
242
-
243
- font-size: 1rem;
244
-
245
- }
246
-
247
-
248
-
249
- &__linkText {
250
-
251
- display: block;
252
-
253
- text-align: right;
254
-
255
-
256
-
257
- a {
258
-
259
- color: inherit;
260
-
261
- font-size: 1rem;
262
-
263
- line-height: 1;
264
-
265
- }
266
-
267
- }
268
-
269
-
270
-
271
- &__list {
272
-
273
- display: flex;
274
-
275
- justify-content: space-between;
276
-
277
- }
278
-
279
- }
280
-
281
-
282
-
283
- .weather-detail {
284
-
285
- flex: 1;
286
-
287
-
288
-
289
- &:not(:first-child) {
290
-
291
- margin-left: 1rem;
292
-
293
- }
294
-
295
-
296
-
297
- &__title {
298
-
299
- margin-bottom: 1rem;
300
-
301
- font-size: 1.6rem;
302
-
303
- font-weight: normal;
304
-
305
- color: inherit;
306
-
307
- }
308
-
309
-
310
-
311
- &__body {
312
-
313
- display: flex;
314
-
315
- align-items: center;
316
-
317
- }
318
-
319
-
320
-
321
- &__icon {
322
-
323
- max-width: 100px;
324
-
325
- margin-left: -1.5rem;
326
-
327
-
328
-
329
- img {
330
-
331
- max-width: 100%;
332
-
333
- max-height: 100%;
334
-
335
- }
336
-
337
- }
338
-
339
-
340
-
341
- .temp {
342
-
343
- &::after {
344
-
345
- margin-left: .8rem;
346
-
347
- content: '℃';
348
-
349
- }
350
-
351
- }
352
-
353
-
354
-
355
- .temp-slash {
356
-
357
- margin: 0 .4rem;
358
-
359
- }
360
-
361
-
362
-
363
- .precip {
364
-
365
- &::after {
366
-
367
- margin-left: .4rem;
368
-
369
- content: '%';
370
-
371
- }
372
-
373
- }
374
-
375
- }
376
-
377
-
378
-
379
- .pc {
380
-
381
- .weather {
382
-
383
- height: 255px;
384
-
385
- background-image: url('/images/common/weather/bg/cloudy_pc.png');
386
-
387
-
388
-
389
- &.sunny {
390
-
391
- background-image: url('/images/common/weather/bg/sunny_pc.png');
392
-
393
- }
394
-
395
-
396
-
397
- &.rainy1 {
398
-
399
- background-image: url('/images/common/weather/bg/rainy1_pc.png');
400
-
401
- }
402
-
403
-
404
-
405
- &.rainy2 {
406
-
407
- background-image: url('/images/common/weather/bg/rainy2_pc.png');
408
-
409
- }
410
-
411
-
412
-
413
- &.snowy1 {
414
-
415
- background-image: url('/images/common/weather/bg/snowy1_pc.png');
416
-
417
- }
418
-
419
-
420
-
421
- &.snowy2 {
422
-
423
- background-image: url('/images/common/weather/bg/snowy2_pc.png');
424
-
425
- }
426
-
427
-
428
-
429
- &__container {
430
-
431
- padding: 2rem;
432
-
433
- }
434
-
435
-
436
-
437
- &__linkText a {
438
-
439
- font-size: 1.5rem;
440
-
441
- }
442
-
443
-
444
-
445
- &__area {
446
-
447
- font-size: 1.8rem;
448
-
449
- }
450
-
451
-
452
-
453
- &__date {
454
-
455
- font-size: 1.5rem;
456
-
457
- }
458
-
459
- }
460
-
461
-
462
-
463
- .weather-detail {
464
-
465
- width: 200px;
466
-
467
-
468
-
469
- &__icon {
470
-
471
- margin-left: -.5rem;
472
-
473
- }
474
-
475
- }
476
-
477
- }
478
-
479
- ```
480
-
481
-
482
-
483
- ```scss
484
-
485
- .list-item {
486
-
487
- box-sizing: border-box;
488
-
489
- position: relative;
490
-
491
- display: flex;
492
-
493
- align-items: center;
494
-
495
- width: 100%;
496
-
497
- min-height: 43px;
498
-
499
- padding: .5rem 1.5rem;
500
-
501
- color: #3c3c3c;
502
-
503
- background-color: white;
504
-
505
- border-bottom: 1px solid #cfcfcf;
506
-
507
- @include PC {
508
-
509
- min-height: 50px;
510
-
511
- }
512
-
513
- @extend %link-overlay;
514
-
515
- .list-item-content {
516
-
517
- display: flex;
518
-
519
- flex-wrap: wrap;
520
-
521
- justify-content: flex-start;
522
-
523
- align-items: center;
524
-
525
- align-content: center;
526
-
527
- width: 100%;
528
-
529
- min-height: calc(43px - 1rem);
530
-
531
- // IEのみテキストの位置がずれるため調整
532
-
533
- @media screen\0 {
534
-
535
- padding-top: .45rem;
536
-
537
- }
538
-
539
- .title {
540
-
541
- width: 100%;
542
-
543
- font-size: 13px;
544
-
545
- overflow: hidden;
546
-
547
- white-space: nowrap;
548
-
549
- text-overflow: ellipsis;
550
-
551
- @include PC {
552
-
553
- font-size: 15px;
554
-
555
- }
556
-
557
- }
558
-
559
- .badge-wrap {
560
-
561
- position: absolute;
562
-
563
- right: 2.0em;
564
-
565
- top: 50%;
566
-
567
- transform: translateY(-50%);
568
-
569
- }
570
-
571
- }
572
-
573
- }
574
-
575
-
576
-
577
- .list-item {
578
-
579
- .icon {
580
-
581
- width: 24px;
582
-
583
- font-size: 20px;
584
-
585
- text-align: center;
586
-
587
- }
588
-
589
- }
590
-
591
-
592
-
593
- // アイコン
594
-
595
- .list-item .icon {
596
-
597
- // デフォは非表示
598
-
599
- display: none;
600
-
601
- margin-right: .5em;
602
-
603
- }
604
-
605
- .list-item.garbage .icon {
606
-
607
- display: block;
608
-
609
- &::before {
610
-
611
- content: $fa-var-trash-o;
612
-
613
- }
614
-
615
- }
616
-
617
- .list-item.tenant_guide .icon {
618
-
619
- display: block;
620
-
621
- &::before {
622
-
623
- content: $fa-var-compass;
624
-
625
- }
626
-
627
- }
628
-
629
- .list-item.facility_manual .icon {
630
-
631
- display: block;
632
-
633
- &::before {
634
-
635
- content: $fa-var-wrench;
636
-
637
- }
638
-
639
- }
640
-
641
- .list-item.contract .icon {
642
-
643
- display: block;
644
-
645
- &::before {
646
-
647
- content: $fa-var-file-o;
648
-
649
- }
650
-
651
- }
652
-
653
- .list-item.leave_contact .icon {
654
-
655
- display: block;
656
-
657
- &::before {
658
-
659
- content: $fa-var-ban;
660
-
661
- }
662
-
663
- }
664
-
665
- .list-item.emergent_contact .icon {
666
-
667
- display: block;
668
-
669
- &::before {
670
-
671
- content: $fa-var-phone;
672
-
673
- }
674
-
675
- }
676
-
677
- .list-item.service_contact .icon {
678
-
679
- display: block;
680
-
681
- &::before {
682
-
683
- content: $fa-var-comment-o;
684
-
685
- }
686
-
687
- }
688
-
689
- .list-item.move_contact .icon {
690
-
691
- display: block;
692
-
693
- &::before {
694
-
695
- content: $fa-var-home;
696
-
697
- }
698
-
699
- }
700
-
701
- .list-item.report .icon {
702
-
703
- display: block;
704
-
705
- &::before {
706
-
707
- content: $fa-var-file-text-o;
708
-
709
- }
710
-
711
- }
712
-
713
- .list-item.help_category .icon {
714
-
715
- display: block;
716
-
717
- &::before {
718
-
719
- content: $fa-var-book;
720
-
721
- }
722
-
723
- }
724
-
725
- .list-item.support .icon {
726
-
727
- display: block;
728
-
729
- &::before {
730
-
731
- content: $fa-var-question-circle;
732
-
733
- }
734
-
735
- }
736
-
737
- ```

2

webpackの設定を追記しました

2018/11/06 08:35

投稿

sugishio
sugishio

スコア47

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,90 @@
18
18
 
19
19
 
20
20
 
21
+ ## webpack設定(一部抜粋)
22
+
23
+
24
+
25
+ ```js
26
+
27
+ 'use strict';
28
+
29
+
30
+
31
+ const ExtractTextPlugin = require('extract-text-webpack-plugin');
32
+
33
+ module.exports = {
34
+
35
+ module: {
36
+
37
+ loaders: [
38
+
39
+ {
40
+
41
+ test: /.vue$/,
42
+
43
+ loader: 'vue-loader',
44
+
45
+ options: {
46
+
47
+ extractCSS: true,
48
+
49
+ loaders: {
50
+
51
+ js: 'babel-loader',
52
+
53
+ file: 'url-loader',
54
+
55
+ scss: 'vue-style-loader!css-loader?sourceMap!postcss-loader?sourceMap!resolve-url-loader?sourceMap!sass-loader?sourceMap',
56
+
57
+ sass: 'vue-style-loader!css-loader?sourceMap!postcss-loader?sourceMap!resolve-url-loader?sourceMap!sass-loader?sourceMap&indentedSyntax'
58
+
59
+ }
60
+
61
+ }
62
+
63
+ },
64
+
65
+ {
66
+
67
+ test: /.(scss|sass|css)$/i,
68
+
69
+ use: ExtractTextPlugin.extract({
70
+
71
+ fallback: 'style-loader',
72
+
73
+ use: [
74
+
75
+ { loader: 'css-loader' },
76
+
77
+ { loader: 'postcss-loader', options: { sourceMap: true } },
78
+
79
+ 'resolve-url-loader',
80
+
81
+ { loader: 'sass-loader', options: { sourceMap: true } }
82
+
83
+ ]
84
+
85
+ })
86
+
87
+ },
88
+
89
+ ]
90
+
91
+ },
92
+
93
+ plugins: [
94
+
95
+ new ExtractTextPlugin('[name].css'),
96
+
97
+ ]
98
+
99
+ }
100
+
101
+ ```
102
+
103
+
104
+
21
105
  ## headタグ内に埋め込まれたままのcss(scss)
22
106
 
23
107
 

1

タグが間違っていたので変更しました

2018/11/06 07:48

投稿

sugishio
sugishio

スコア47

test CHANGED
File without changes
test CHANGED
File without changes