Skip to content

Commit 7ebc1ab

Browse files
committed
add orderPreprocessors option
1 parent 1f66d6d commit 7ebc1ab

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export default {
4646
}
4747
},
4848

49+
// Preprocessors will be applied in the order passed down to preprocess
50+
// Default is (markup, then script, then style)
51+
orderPreprocessors: false,
52+
4953
// Emit CSS as "files" for other plugins to process
5054
emitCss: true,
5155

index.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const pluginOptions = {
3131
extensions: true,
3232
emitCss: true,
3333
preprocess: true,
34+
orderPreprocessors: true,
3435

3536
// legacy — we might want to remove/change these in a future version
3637
onwarn: true,
@@ -219,22 +220,34 @@ module.exports = function svelte(options = {}) {
219220
}
220221
return resp;
221222
}
222-
);
223+
)
223224
};
224225
}
225-
preprocessPromise = preprocess(
226-
code,
227-
Object.assign(preprocessOptions, { filename: id })
228-
).then(code => code.toString());
226+
preprocessPromise = preprocess(
227+
code,
228+
Object.assign(preprocessOptions, { filename: id })
229+
).then(code => code.toString());
229230
} else {
230-
preprocessPromise = preprocess(code, options.preprocess, {
231-
filename: id
232-
}).then(processed => {
233-
if (processed.dependencies) {
234-
dependencies.push(...processed.dependencies);
235-
}
236-
return processed.toString();
237-
});
231+
if (options.orderPreprocessors) {
232+
preprocessPromise = options.preprocess.reduce((acc, cur) => {
233+
return Promise.resolve(acc).then(code => {
234+
return preprocess(
235+
code.code,
236+
cur,
237+
{ filename: id }
238+
)
239+
})
240+
}, { code }).then(code => code.toString());
241+
} else {
242+
preprocessPromise = preprocess(code, options.preprocess, {
243+
filename: id
244+
}).then(processed => {
245+
if (processed.dependencies) {
246+
dependencies.push(...processed.dependencies);
247+
}
248+
return processed.toString();
249+
});
250+
}
238251
}
239252
} else {
240253
preprocessPromise = Promise.resolve(code);

0 commit comments

Comments
 (0)