Created
June 10, 2018 23:51
-
-
Save delikat/e81d659f2734c24f850aace0862996eb to your computer and use it in GitHub Desktop.
Modular antd imports with next.js, next-less, and next-typescript
This file contains 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 withLess = require('@zeit/next-less') | |
const withTypescript = require('@zeit/next-typescript') | |
const resolve = require('resolve') | |
module.exports = withTypescript(withLess({ | |
lessLoaderOptions: { | |
javascriptEnabled: true, | |
// place antd theme overrides here | |
modifyVars: {'@primary-color': '#1Dd57A'} | |
}, | |
webpack: (config, { buildId, dev, isServer, dir, defaultLoaders }) => { | |
defaultLoaders.babel.options.plugins.push(['@babel/plugin-proposal-decorators', { legacy: true }]) | |
defaultLoaders.babel.options.plugins.push(['import', { | |
'libraryName': 'antd', | |
'style': true | |
}]) | |
config.externals = [] | |
if (isServer) { | |
config.externals.push((context, request, callback) => { | |
resolve(request, { basedir: dir, preserveSymlinks: true }, (err, res) => { | |
if (err) { | |
return callback() | |
} | |
// exclude webpack itself and antd from externals | |
if (res.match(/node_modules[/\\].*\.js/) && !res.match(/node_modules[/\\]webpack/) && !res.match(/node_modules[/\\]antd/)) { | |
return callback(null, `commonjs ${request}`) | |
} | |
callback() | |
}) | |
}) | |
} | |
return config | |
}, | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment