Skip to content

Commit 84ffe7f

Browse files
refactor: postcss option
1 parent 1330534 commit 84ffe7f

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"webpack": "^4.0.0"
4343
},
4444
"dependencies": {
45-
"loader-utils": "^1.0.2",
46-
"postcss": "^7.0.2",
45+
"loader-utils": "^1.0.0",
46+
"postcss": "^7.0.0",
4747
"postcss-value-parser": "^3.3.0",
4848
"schema-utils": "^1.0.0"
4949
},

src/index.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,24 @@ export default function loader(content, map, meta) {
7171
prevMap.sourceRoot = '';
7272
}
7373

74-
const postcssOptions = {
75-
// We need a prefix to avoid path rewriting of PostCSS
76-
from: `/css-loader!${getRemainingRequest(this)
77-
.split('!')
78-
.pop()}`,
79-
to: getCurrentRequest(this)
80-
.split('!')
81-
.pop(),
82-
map: sourceMap
83-
? {
84-
prev: prevMap,
85-
sourcesContent: true,
86-
inline: false,
87-
annotation: false,
88-
}
89-
: null,
90-
};
91-
9274
postcss(plugins)
93-
.process(contentOrAst, postcssOptions)
75+
.process(contentOrAst, {
76+
// We need a prefix to avoid path rewriting of PostCSS
77+
from: `/css-loader!${getRemainingRequest(this)
78+
.split('!')
79+
.pop()}`,
80+
to: getCurrentRequest(this)
81+
.split('!')
82+
.pop(),
83+
map: sourceMap
84+
? {
85+
prev: prevMap,
86+
sourcesContent: true,
87+
inline: false,
88+
annotation: false,
89+
}
90+
: null,
91+
})
9492
.then((result) => {
9593
result
9694
.warnings()

test/__snapshots__/loader.test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ exports[`loader basic: runtime 1`] = `
6464
6565
/* eslint-disable */
6666
67-
// CSS (Loader) Runtime
67+
// CSS Loader (Runtime)
6868
module.exports = function (useSourceMap) {
6969
const list = [];
7070
71-
// return the list of modules as css string
71+
// Return the list of modules as css string
7272
list.toString = function toString() {
7373
return this.map(function (item) {
7474
const content = cssWithMappingToString(item, useSourceMap);
@@ -81,7 +81,7 @@ module.exports = function (useSourceMap) {
8181
}).join('');
8282
};
8383
84-
// import a list of modules into the list
84+
// Import a list of modules into the list
8585
list.i = function (modules, mediaQuery) {
8686
if (typeof modules === 'string') {
8787
modules = [[null, modules, '']];
@@ -100,10 +100,10 @@ module.exports = function (useSourceMap) {
100100
for (let i = 0; i < modules.length; i++) {
101101
const item = modules[i];
102102
103-
// skip already imported module
104-
// this implementation is not 100% perfect for weird media query combinations
103+
// Skip already imported module.
104+
// This implementation is not 100% perfect for weird media query combinations
105105
// when a module is imported multiple times with different media queries.
106-
// I hope this will never occur (Hey this way we have smaller bundles)
106+
// I hope this will never occur (Hey this way we have smaller bundles).
107107
if (typeof item[0] !== 'number' || !isImported[item[0]]) {
108108
if (mediaQuery && !item[2]) {
109109
item[2] = mediaQuery;

0 commit comments

Comments
 (0)