forked from webpack-contrib/extract-text-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically apply source-maps based on webpack config
Source-maps do not work for CSS when you base64 encode them, yet it would be nice to to facilitate dynamically applying source-maps using `webpack -d`. This will apply the sourceMap query param to the css-loader if a devtool option is selected in the webpack config. Relates to webpack-contrib/less-loader#36 Relates to webpack-contrib/css-loader#40
- Loading branch information
Showing
6 changed files
with
148 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 2 | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function applyToLoaders(loaders) { | ||
return loaders.map(function(loader){ | ||
if (loader.indexOf('?') !== -1) { | ||
return loader; | ||
} | ||
|
||
return loader.replace(/css(-loader)?/, '$&?sourceMap'); | ||
}); | ||
} | ||
|
||
function splitAndApplyToLoader(loader) { | ||
var loaders = loader.split('!'); | ||
return applyToLoaders(loaders).join('!'); | ||
} | ||
|
||
module.exports = { | ||
applyParam: function(loaders) { | ||
return loaders.map(function(loader){ | ||
if (loader.loader) { | ||
loader.loader = splitAndApplyToLoader(loader.loader); | ||
} else { | ||
loader.loaders = applyToLoaders(loader.loaders); | ||
} | ||
return loader; | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
{ | ||
"name": "extract-text-webpack-plugin", | ||
"version": "0.3.8", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "Extract text from bundle into a file.", | ||
"peerDependencies": { | ||
"webpack": "^1.4.2" | ||
}, | ||
"dependencies": { | ||
"async": "~0.2.10", | ||
"source-map": "~0.1.38", | ||
"loader-utils": "~0.2.3" | ||
}, | ||
"devDependencies": { | ||
"file-loader": "*", | ||
"style-loader": "*", | ||
"css-loader": "*", | ||
"webpack": "*" | ||
}, | ||
"homepage": "http://github.com/webpack/extract-text-webpack-plugin", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/webpack/extract-text-webpack-plugin.git" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
] | ||
"name": "extract-text-webpack-plugin", | ||
"version": "0.3.8", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "Extract text from bundle into a file.", | ||
"peerDependencies": { | ||
"webpack": "^1.4.2" | ||
}, | ||
"dependencies": { | ||
"async": "~0.2.10", | ||
"source-map": "~0.1.38", | ||
"loader-utils": "~0.2.3" | ||
}, | ||
"devDependencies": { | ||
"css-loader": "*", | ||
"file-loader": "*", | ||
"mocha": "^2.1.0", | ||
"should": "^5.0.1", | ||
"style-loader": "*", | ||
"webpack": "*" | ||
}, | ||
"homepage": "http://github.com/webpack/extract-text-webpack-plugin", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/webpack/extract-text-webpack-plugin.git" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var should = require('should'); | ||
var sourceMapSupport = require('../lib/SourceMapSupport'); | ||
|
||
describe('SourceMapSupportTestCases', function() { | ||
it('should add sourceMap query parameter to "css-loader" [loader string]', function() { | ||
var loaders = [{ | ||
loader: 'style-loader!css-loader!less-loader' | ||
}]; | ||
|
||
var result = sourceMapSupport.applyParam(loaders); | ||
result[0].loader.should.equal('style-loader!css-loader?sourceMap!less-loader'); | ||
}); | ||
|
||
it('should add sourceMap query parameter to "css-loader" [loaders array]', function() { | ||
var loaders = [{ | ||
loaders: [ | ||
'style-loader', | ||
'css-loader', | ||
'less-loader' | ||
] | ||
}]; | ||
|
||
var result = sourceMapSupport.applyParam(loaders); | ||
should.deepEqual([ | ||
'style-loader', | ||
'css-loader?sourceMap', | ||
'less-loader' | ||
], result[0].loaders); | ||
}); | ||
|
||
it('should add sourceMap query parameter to "css" [loader string]', function() { | ||
var loaders = [{ | ||
loader: 'style!css!less' | ||
}]; | ||
|
||
var result = sourceMapSupport.applyParam(loaders); | ||
result[0].loader.should.equal('style!css?sourceMap!less'); | ||
}); | ||
|
||
it('should add sourceMap query parameter to "css" [loaders array]', function() { | ||
var loaders = [{ | ||
loaders: [ | ||
'style', | ||
'css', | ||
'less' | ||
] | ||
}]; | ||
|
||
var result = sourceMapSupport.applyParam(loaders); | ||
should.deepEqual([ | ||
'style', | ||
'css?sourceMap', | ||
'less' | ||
], result[0].loaders); | ||
}); | ||
|
||
it('should not add sourceMap query parameter to "css-loader" with pre-existing params [loader string]', function() { | ||
var loaders = [{ | ||
loader: 'style-loader!css-loader?blah!less-loader' | ||
}]; | ||
|
||
var result = sourceMapSupport.applyParam(loaders); | ||
result[0].loader.should.equal('style-loader!css-loader?blah!less-loader'); | ||
}); | ||
}); |