Skip to content

Instantly share code, notes, and snippets.

@fedek6
Created August 12, 2021 13:04
Show Gist options
  • Select an option

  • Save fedek6/2a59344c2d17ac5754ffb990c91cc86e to your computer and use it in GitHub Desktop.

Select an option

Save fedek6/2a59344c2d17ac5754ffb990c91cc86e to your computer and use it in GitHub Desktop.
Custom loader for Webpack (in Next.js)
module.exports = function (source) {
console.log("The original file was here:", this.resourcePath);
console.log(source);
return source;
};
const withLinaria = require("next-linaria");
const path = require("path");
module.exports = withLinaria({
reactStrictMode: true,
webpack: (config) => {
const mutatedConfig = config;
// Position 0
const loaders = {
"custom-loader": path.resolve("./loader.js"),
...mutatedConfig.resolveLoader.alias,
};
mutatedConfig.resolveLoader.alias = loaders;
console.log(mutatedConfig.resolveLoader.alias);
mutatedConfig.module.rules.push({
test: /\.js$/i,
use: [
{
loader: "custom-loader",
},
],
});
return mutatedConfig;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment