Created
August 12, 2021 13:04
-
-
Save fedek6/2a59344c2d17ac5754ffb990c91cc86e to your computer and use it in GitHub Desktop.
Custom loader for Webpack (in Next.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function (source) { | |
| console.log("The original file was here:", this.resourcePath); | |
| console.log(source); | |
| return source; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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