Skip to content

Commit ede061d

Browse files
refactor: options
1 parent 45469b7 commit ede061d

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/loader.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module.exports = function(content, map, meta) {
1515

1616
const cb = this.async();
1717
const sourceMap = options.sourceMap || false;
18+
const url = typeof options.url === "undefined" ? true : options.url;
19+
const importOpt = typeof options.import === "undefined" ? true : options.import;
20+
const importLoaders = options.importLoaders || 0;
1821

1922
if (sourceMap && map) {
2023
if (typeof map === "string") {
@@ -42,9 +45,9 @@ module.exports = function(content, map, meta) {
4245
const plugins = [
4346
plugin({
4447
loaderContext: this,
45-
url: options.url !== false,
46-
import: options.import !== false,
47-
importLoaders: options.importLoaders
48+
url,
49+
import: importOpt,
50+
importLoaders
4851
})
4952
];
5053

@@ -114,11 +117,11 @@ module.exports = function(content, map, meta) {
114117
result.messages
115118
.filter(
116119
message =>
117-
message.type === "modify-generated-code" ? message : false
120+
message.type === "modify-code" ? message : false
118121
)
119122
.forEach((message) => {
120123
try {
121-
newContentObj = message.modifyGeneratedCode(this, newContentObj);
124+
newContentObj = message.modifyCode(this, newContentObj);
122125
} catch (err) {
123126
this.emitError(err);
124127
}

lib/plugin.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ const loaderUtils = require("loader-utils");
55
const pluginName = "postcss-css-loader";
66

77
function getImportPrefix(loaderContext, importLoaders) {
8-
if (importLoaders === false) {
9-
return "";
10-
}
11-
12-
const importLoadersValue = parseInt(importLoaders, 10) || 0;
138
const loadersRequest = loaderContext.loaders
149
.slice(
1510
loaderContext.loaderIndex,
16-
loaderContext.loaderIndex + 1 + importLoadersValue
11+
loaderContext.loaderIndex + 1 + importLoaders
1712
)
1813
.map(x => x.request)
1914
.join("!");
@@ -81,8 +76,8 @@ module.exports = postcss.plugin(pluginName, function(options) {
8176
if (!alreadyImported[url]) {
8277
result.messages.push({
8378
pluginName,
84-
type: "modify-generated-code",
85-
modifyGeneratedCode: (loaderContext, contentObj) => {
79+
type: "modify-code",
80+
modifyCode: (loaderContext, contentObj) => {
8681
contentObj.runtime = `${contentObj.runtime}${runtimeCode}\n`;
8782

8883
return contentObj;
@@ -148,8 +143,8 @@ module.exports = postcss.plugin(pluginName, function(options) {
148143

149144
result.messages.push({
150145
pluginName,
151-
type: "modify-generated-code",
152-
modifyGeneratedCode: (loaderContext, contentObj) => {
146+
type: "modify-code",
147+
modifyCode: (loaderContext, contentObj) => {
153148
if (!hasURLEscapeRuntimeCode) {
154149
contentObj.imports = `var runtimeEscape = require(${loaderUtils.stringifyRequest(
155150
loaderContext,

0 commit comments

Comments
 (0)