Skip to content

Instantly share code, notes, and snippets.

@trinwin
Last active August 3, 2020 21:22
Show Gist options
  • Save trinwin/a1ab37f534658aa893c287dabd773f04 to your computer and use it in GitHub Desktop.
Save trinwin/a1ab37f534658aa893c287dabd773f04 to your computer and use it in GitHub Desktop.
const path = require('path');
module.exports = {
webpackFinal: async (baseConfig, options) => {
const { module = {} } = baseConfig;
const newConfig = {
...baseConfig,
module: {
...module,
rules: [...(module.rules || [])],
},
};
// TypeScript
newConfig.module.rules.push({
test: /\.(ts|tsx)$/,
include: [path.resolve(__dirname, '../components')],
use: [
{
loader: 'babel-loader',
options: {
presets: ['next/babel', require.resolve('babel-preset-react-app')],
plugins: ['react-docgen'],
},
},
],
});
newConfig.resolve.extensions.push('.ts', '.tsx');
// SCSS
newConfig.module.rules.push({
test: /\.(s*)css$/,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../styles/global.scss'),
});
// If you are using CSS Modules, check out the setup from Justin (justincy)
// Many thanks to Justin for the inspiration
// https://gist.github.com/justincy/b8805ae2b333ac98d5a3bd9f431e8f70#file-next-preset-js
return newConfig;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment