0.1.0 • Published 4 years ago
@azimutlabs/config-next v0.1.0
@azimutlabs/config-next
Next.js config extensions.
We assume that you already have next
package installed.
withEslint
- addseslint
.- usage:
// next.config.js module.exports = withEslint({ // nextOptions eslintOptions: {} // options for eslint-loader });
- required libs:
eslint
,eslint-loader
,eslint-friendly-formatter
. - download command:
npm i -D eslint-loader eslint-friendly-formatter
- usage:
withEnv
- adds env variables usingnext/config
runtime configurations.usage:
// next.config.js module.exports = withEnv({ // nextOptions serverRuntimeConfig: {}, // optional variables for server config. publicRuntimeConfig: {}, // optional variables for both server and public config. }); // .env // NEXT_PUBLIC_TEST=somevalue // pages/index.js import getConfig from 'next/config'; const { NEXT_PUBLIC_TEST } = getConfig().publicRuntimeConfig;
to override env var prefixes you need to define variables:
# .env # Prefix for serverRuntimeConfig SERVER_PREFIX=_ # Prefix for publicRuntimeConfig PUBLIC_PREFIX=CLIENT_ _PORT=3000 CLIENT_API=api.github.com
recommended libs:
dotenv-load
withLodash
- optimizeslodash
dist size usingbabel-plugin-lodash
andlodash-webpack-plugin
.- usage:
// next.config.js module.exports = withLodash({ // nextOptions babelPluginLodashOptions: {}, // babel-plugin-lodash options. lodashWebpackPluginOptions: {}, // lodash-webpack-plugin options. });
- required libs:
babel-plugin-lodash
,lodash-webpack-plugin
. - download command:
npm i -D babel-plugin-lodash lodash-webpack-plugin
- usage:
withStylelint
- addsstylelint-webpack-plugin
forstylelint
.- usage:
// next.config.js module.exports = withStylelint({ // nextOptions stylelintWebpackPluginOptions: {}, // stylelint-webpack-plugin options. });
- required libs:
stylelint
,stylelint-webpack-plugin
. - download command:
npm i -D stylelint stylelint-webpack-plugin
- usage:
withEmotion
- adds@emotion/babel-preset-css-prop
for@emotion/core
.- ⚠️ NOTE: for some reason,
next.js
does not usepresets
that was injected intonext-babel-loader
's options without creating.babelrc
file. To make your project stay clean, you can configure yourbabel
inpackage.json
:{ "babel": { "presets": ["next/babel"] } }
- usage:
// next.config.js module.exports = withEmotion({ // nextOptions babelPresetEmotionOptions: {}, // @emotion/babel-preset-css-prop options. });
- required libs:
@emotion/core
,@emotion/babel-preset-css-prop
. - download command:
npm i -D @emotion/core @emotion/babel-preset-css-prop
- ⚠️ NOTE: for some reason,
withSass
- addsscss
,scss-modules
,sass-lint
(nocss
).- ❗️DEPRECATED❗ - we are planning to move into CSS-in-JS practise, so for now this extension is no longer maintained.️
- usage:
// next.config.js module.exports = withSass({ // nextOptions sassLintOptions: {} // options for sass-lint-webpack plugin });
- to enable
sass-lint
- addsassLintOptions
field intonextOptions
as shown inusage
section. - required libs:
@zeit/next-sass
- required libs for sass-lint:
sass-lint
,sass-lint-webpack
- download command:
npm i -D @zeit/next-sass
Recommended usage
Combine by composing functions:
module.exports = compose(
withEslint,
withSass,
withEnv,
)({ // next config
eslintConfig: {},
sassLintConfig: {},
});