Skip to content

Make filename relative #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ module.exports = function svelte(options = {}) {
if (!filter(id)) return null;

const extension = path.extname(id);

if (!~extensions.indexOf(extension)) return null;


const filename = path.relative(process.cwd(), id);

const dependencies = [];
let preprocessPromise;
if (options.preprocess) {
Expand All @@ -246,12 +247,10 @@ module.exports = function svelte(options = {}) {
}
preprocessPromise = preprocess(
code,
Object.assign(preprocessOptions, { filename: id })
Object.assign(preprocessOptions, { filename })
).then(code => code.toString());
} else {
preprocessPromise = preprocess(code, options.preprocess, {
filename: id
}).then(processed => {
preprocessPromise = preprocess(code, options.preprocess, { filename }).then(processed => {
if (processed.dependencies) {
dependencies.push(...processed.dependencies);
}
Expand All @@ -273,9 +272,7 @@ module.exports = function svelte(options = {}) {

const compiled = compile(
code,
Object.assign(base_options, fixed_options, {
filename: id
}, major_version >= 3 ? null : {
Object.assign(base_options, fixed_options, { filename }, major_version >= 3 ? null : {
name: capitalize(sanitize(id))
})
);
Expand Down Expand Up @@ -314,6 +311,7 @@ module.exports = function svelte(options = {}) {
return compiled.js;
});
},

/**
* If css: true then outputs a single file with all CSS bundled together
*/
Expand Down