Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
04c3d16
refactor: drop `css` modules
alexander-akait Jul 9, 2018
09e21c1
refactor: `runtime` code
alexander-akait Jul 9, 2018
c012f9b
refactor: move `postcss` plugin into own file
alexander-akait Jul 9, 2018
b130031
refactor: move `CssLoaderError` into own file
alexander-akait Jul 9, 2018
d1f80ee
refactor: merge code from `processCss` with `loader` code
alexander-akait Jul 9, 2018
ebdaf84
refactor: drop export locals
alexander-akait Jul 9, 2018
8150d2b
refactor: drop `icss` utils
alexander-akait Jul 9, 2018
f95be98
refactor: some stuff
alexander-akait Jul 9, 2018
c81edd4
refactor: `url` part of plugin
alexander-akait Jul 10, 2018
c49b5da
refactor: `import` part of plugin
alexander-akait Jul 10, 2018
254be6b
refactor: stuff
alexander-akait Jul 10, 2018
d22c14f
refactor: escape
alexander-akait Jul 10, 2018
cddbea5
refactor: rename `escape` to `runtimeEscape`
alexander-akait Jul 10, 2018
186f5b6
refactor: `getImportPrefix`
alexander-akait Jul 10, 2018
aa3918a
refactor: loader
alexander-akait Jul 10, 2018
7570df9
refactor: tests
alexander-akait Jul 10, 2018
ff7a4c8
refactor: SyntaxError class
alexander-akait Jul 10, 2018
2f769b3
refactor: loader
alexander-akait Jul 10, 2018
fdfdc17
refactor: use `runtime` message api
alexander-akait Jul 11, 2018
f424b92
refactor: `url` in lowercase
alexander-akait Jul 11, 2018
1aaecdd
refactor: rename `modify-runtime` to `modify-runtime-code`
alexander-akait Jul 11, 2018
45469b7
refactor: `loader` and `plugin`
alexander-akait Jul 11, 2018
ede061d
refactor: options
alexander-akait Jul 12, 2018
9075cfc
feat: validate options
alexander-akait Jul 12, 2018
99ffe87
tests: escaped characters
alexander-akait Jul 12, 2018
81d104a
refactor: webpack-defaults
alexander-akait Jul 12, 2018
f0c5312
refactor: tests
alexander-akait Aug 7, 2018
ae51bf0
refactor: modify message api
alexander-akait Aug 7, 2018
9ad9e21
chore(deps): update postcss to `7` version
alexander-akait Aug 8, 2018
1fdc462
chore(deps): use `schema-utils`
alexander-akait Aug 8, 2018
64a5b48
refactor: SyntaxError and Warning
alexander-akait Aug 8, 2018
0aea5d7
refactor: stuff
alexander-akait Aug 8, 2018
1554d66
test: fix
alexander-akait Aug 8, 2018
ca846b4
refactor: comment
alexander-akait Aug 8, 2018
1330534
refactor: stuff
alexander-akait Aug 8, 2018
84ffe7f
refactor: postcss option
alexander-akait Aug 8, 2018
fe0b78e
test: more
alexander-akait Aug 8, 2018
2b758e8
refactor: remove unnecessary map check
alexander-akait Aug 8, 2018
063dd2d
chore: update `postcss-loader`
alexander-akait Aug 8, 2018
868a5c3
feat: custom error messages
alexander-akait Aug 8, 2018
d49b1db
fix: test
alexander-akait Aug 8, 2018
c4037b0
refactor: reuing ast
alexander-akait Aug 8, 2018
f9cc7ba
docs: note about `css` modules
alexander-akait Aug 8, 2018
eab41ba
fix: use postcss ast only if versions is equals
alexander-akait Aug 15, 2018
06e6d08
refactor: tests
alexander-akait Aug 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: import part of plugin
  • Loading branch information
alexander-akait committed Jul 10, 2018
commit c49b5da9df97012b36c3567d3d48383cd1970af5
50 changes: 32 additions & 18 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var postcss = require("postcss");
var valueParser = require("postcss-value-parser");
var Tokenizer = require("css-selector-tokenizer");
var loaderUtils = require("loader-utils");
const postcss = require("postcss");
const valueParser = require("postcss-value-parser");
const loaderUtils = require("loader-utils");

module.exports = postcss.plugin("css-loader-parser", function(options) {
return function(css) {
Expand All @@ -10,38 +9,53 @@ module.exports = postcss.plugin("css-loader-parser", function(options) {

if (options.import) {
css.walkAtRules(/^import$/i, function(rule) {
const values = Tokenizer.parseValues(rule.params);
let url = values.nodes[0].nodes[0];
const parsedValue = valueParser(rule.params);

if (url && url.type === "url") {
url = url.url;
} else if (url && url.type === "string") {
url = url.value;
} else throw rule.error("Unexpected format " + rule.params);

if (!url.replace(/\s/g, "").length) {
return;
if (!parsedValue.nodes || !parsedValue.nodes[0]) {
throw rule.error("Unexpected format " + rule.params);
}

values.nodes[0].nodes.shift();
const firstNode = parsedValue.nodes[0];

let url = null;

if (
firstNode.type === "function" &&
firstNode.value.toLowerCase() === "url"
) {
if (firstNode.nodes[0]) {
firstNode.nodes[0].quote = "";
}

url = valueParser.stringify(firstNode.nodes);
} else if (firstNode.type === "string") {
url = firstNode.value;
}

const mediaQuery = Tokenizer.stringifyValues(values);
if (url.replace(/\s/g, "").length === 0) {
return;
}

if (loaderUtils.isUrlRequest(url)) {
url = loaderUtils.urlToRequest(url);
}

const mediaQuery = valueParser
.stringify(parsedValue.nodes.slice(1))
.trim();

importItems.push({
url: url,
mediaQuery: mediaQuery
});

rule.remove();
});
}

if (options.url) {
css.walkDecls(decl => {
if (!decl.value.includes("url(")) {
if (!/url\(/i.test(decl.value)) {
return decl;
}

Expand All @@ -58,7 +72,7 @@ module.exports = postcss.plugin("css-loader-parser", function(options) {
}

const URLNode = node.nodes[0];
const URLValue = URLNode.value.trim().replace(/\\[\r\n]/, "");
const URLValue = URLNode.value.trim().replace(/\\[\r\n]/g, "");

// Skip empty URLs
// Empty URL function equals request to current stylesheet where it is declared
Expand Down
66 changes: 0 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
],
"dependencies": {
"babel-code-frame": "^6.26.0",
"css-selector-tokenizer": "^0.7.0",
"icss-utils": "^2.1.0",
"loader-utils": "^1.0.2",
"lodash.camelcase": "^4.3.0",
"postcss": "^6.0.23",
"postcss-value-parser": "^3.3.0"
},
Expand Down
Loading