-
Notifications
You must be signed in to change notification settings - Fork 58
Source maps support #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,33 +30,36 @@ class OptimizeCssAssetsWebpackPlugin extends LastCallWebpackPlugin { | |
} | ||
|
||
processCss(assetName, asset, assets) { | ||
const css = asset.source(); | ||
const css = asset.sourceAndMap ? asset.sourceAndMap() : { source: asset.source() }; | ||
const processOptions = Object.assign( | ||
{ from: assetName, to: assetName }, | ||
this.options.cssProcessorOptions || {} | ||
this.options.cssProcessorOptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From MDN:
|
||
); | ||
|
||
if (processOptions.map && !processOptions.map.prev) { | ||
try { | ||
const mapJson = assets.getAsset(assetName + '.map'); | ||
if (mapJson) { | ||
const map = JSON.parse(mapJson); | ||
if ( | ||
map && | ||
( | ||
(map.sources && map.sources.length > 0) || | ||
(map.mappings && map.mappings.length > 0) | ||
) | ||
) { | ||
processOptions.map = Object.assign({ prev: mapJson }, processOptions.map); | ||
let map = css.map; | ||
if (!map) { | ||
const mapJson = assets.getAsset(assetName + '.map'); | ||
if (mapJson) { | ||
map = JSON.parse(mapJson); | ||
} | ||
} | ||
if ( | ||
map && | ||
( | ||
(map.sources && map.sources.length > 0) || | ||
(map.mappings && map.mappings.length > 0) | ||
) | ||
) { | ||
processOptions.map = Object.assign({ prev: map }, processOptions.map); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From PostCSS docs:
|
||
} | ||
} catch (err) { | ||
console.warn('OptimizeCssAssetsPlugin.processCss() Error getting previous source map', err); | ||
} | ||
} | ||
return this.options | ||
.cssProcessor.process(css, processOptions) | ||
.cssProcessor.process(css.source, processOptions) | ||
.then(r => { | ||
if (processOptions.map && r.map && r.map.toString) { | ||
assets.setAsset(assetName + '.map', r.map.toString()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UglifyJS Webpack Plugin also uses
sourceAndMap
function if exists