Skip to content
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

Support aliases #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions src/extractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {
const indexOfLastExclMark = relativePathWithoutQuery.lastIndexOf("!");
const loaders = givenRelativePath.slice(0, indexOfLastExclMark + 1);
const relativePath = relativePathWithoutQuery.slice(indexOfLastExclMark + 1);
const absolutePath = resolve.sync(relativePath, {
const absolutePath = tryResolve(relativePath, {
basedir: path.dirname(filename),
});
const ext = path.extname(absolutePath);
Expand All @@ -138,7 +138,7 @@ function evalDependencyGraph({loaderContext, src, filename, publicPath = ""}) {

// If the required file is a js file, we just require it with node's require.
// If the required file should be processed by a loader we do not touch it (even if it is a .js file).
if (loaders === "" && ext === ".js") {
if (loaders === "" && absolutePath.indexOf("node_modules/") !== -1 && ext === ".js") {
// Mark the file as dependency so webpack's watcher is working for the css-loader helper.
// Other dependencies are automatically added by loadModule() below
loaderContext.addDependency(absolutePath);
Expand Down Expand Up @@ -221,6 +221,14 @@ function getPublicPath(options, context) {
}
/* eslint-enable complexity */

function tryResolve(filename, options) {
try {
return resolve.sync(filename, options);
} catch (e) { // Return original.
return filename;
}
}

// For CommonJS interoperability
module.exports = extractLoader;
export default extractLoader;
2 changes: 1 addition & 1 deletion test/extractLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("extractLoader", () => {
throw new Error("Did not throw expected error");
},
message => {
expect(message).to.match(/Error: Cannot find module '\.\/does-not-exist\.jpg'/);
expect(message).to.match(/Error: Can't resolve '\.\/does-not-exist\.jpg'/);
}
));
it("should report resolve loader errors", () =>
Expand Down