Skip to content

Commit 1809031

Browse files
committed
fix: only generate CSS source map when needed
close #1070
1 parent 6d3c5b2 commit 1809031

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/loader.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ module.exports = function (content) {
8585
const moduleId = 'data-v-' + hash(isProduction ? content : shortFilePath)
8686

8787
let cssLoaderOptions = ''
88-
if (!isProduction && this.sourceMap && options.cssSourceMap !== false) {
88+
const cssSourceMap =
89+
!isProduction &&
90+
this.sourceMap &&
91+
options.cssSourceMap !== false
92+
if (cssSourceMap) {
8993
cssLoaderOptions += '?sourceMap'
9094
}
9195
if (isProduction) {
@@ -97,7 +101,16 @@ module.exports = function (content) {
97101

98102
let output = ''
99103
const bustCache = !isProduction && options.cacheBusting !== false
100-
const parts = parse(content, fileName, this.sourceMap, sourceRoot, bustCache)
104+
105+
const parts = parse(
106+
content,
107+
fileName,
108+
this.sourceMap,
109+
sourceRoot,
110+
bustCache,
111+
cssSourceMap
112+
)
113+
101114
const hasScoped = parts.styles.some(({ scoped }) => scoped)
102115
const templateAttrs =
103116
parts.template && parts.template.attrs && parts.template.attrs

lib/parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const SourceMapGenerator = require('source-map').SourceMapGenerator
66
const splitRE = /\r?\n/g
77
const emptyRE = /^(?:\/\/)?\s*$/
88

9-
module.exports = (content, filename, needMap, sourceRoot, bustCache) => {
9+
module.exports = (content, filename, needMap, sourceRoot, bustCache, needCSSMap) => {
1010
const cacheKey = hash(filename + content)
1111
// source-map cache busting for hot-reloadded modules
1212
const filenameWithHash = bustCache
@@ -24,7 +24,7 @@ module.exports = (content, filename, needMap, sourceRoot, bustCache) => {
2424
sourceRoot
2525
)
2626
}
27-
if (output.styles) {
27+
if (needCSSMap && output.styles) {
2828
output.styles.forEach(style => {
2929
if (!style.src) {
3030
style.map = generateSourceMap(

0 commit comments

Comments
 (0)