Skip to content

Commit

Permalink
Add support for vue single file components (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen authored Apr 4, 2024
1 parent 95cdb22 commit 29fec2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const defaultLookups = {
'.scss': sassLookup,
'.styl': stylusLookup,
'.ts': tsLookup,
'.tsx': tsLookup
'.tsx': tsLookup,
'.vue': vueLookup
};

/**
Expand Down Expand Up @@ -389,6 +390,37 @@ function commonJSLookup(options) {
return result;
}

function vueLookup(options) {
const { dependency } = options;

if (!dependency) {
debug('blank dependency given. Returning early.');
return '';
}

if (dependency.endsWith('.js') || dependency.endsWith('.jsx')) {
return jsLookup(options);
}

if (dependency.endsWith('.ts') || dependency.endsWith('.tsx')) {
return tsLookup(options);
}

if (dependency.endsWith('.scss') || dependency.endsWith('.sass') || dependency.endsWith('.less')) {
return sassLookup(options);
}

if (dependency.endsWith('.styl')) {
return stylusLookup(options);
}

if (options.tsConfig || options.tsConfigPath) {
return tsLookup(options);
}

return jsLookup(options);
}

function resolveWebpackPath({ dependency, filename, directory, webpackConfig }) {
if (!webpackResolve) {
webpackResolve = require('enhanced-resolve');
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('filing-cabinet', () => {
'.scss',
'.styl',
'.ts',
'.tsx'
'.tsx',
'.vue'
].sort();
assert.deepEqual(actual, expected);
});
Expand Down

0 comments on commit 29fec2c

Please sign in to comment.