开发者社区> 镜像站> NPM> next-plugin-custom-babel-config
next-plugin-custom-babel-config
Adds the ability to resolve a custom babel config file when using next.js
Last updated 6 months ago by josephreubenluck .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install next-plugin-custom-babel-config 
SYNC missed versions from official npm registry.

Next.js + Custom babel config file

Adds the ability to supply a custom babel.config.js to next.js projects. Useful if you wish to use a monorepo / yarn workspaces project setup in combination with next.js where a shared babel.config.js is used. More reading

This plugin is intended to be used with next.js > 7.0.0

If you like it, give it a star!

Installation

npm install --save next-plugin-custom-babel-config

or

yarn add next-plugin-custom-babel-config

Usage

Given the directory structure:

- api-workspace
 ㄴ index.js
 ㄴ package.json
- ui-workspace
 ㄴ pages
 ㄴ next.config.js
 ㄴ package.json
- babel.config.js
- package.json

Wrap your config in the plugin in your next.config.js file:

// ui/next.config.js
const path = require("path");
const withCustomBabelConfigFile = require("next-plugin-custom-babel-config");

module.exports = withCustomBabelConfigFile({
  babelConfigFile: path.resolve("../babel.config.js")
});

I need to transpile my workspaces

If you want to import source files from your workspaces, or need to transpile any files inside node_modules, Use the handy next-plugin-transpile-modules package in conjunction with this one as follows:

// ui/next.config.js
const path = require("path");
const withTranspileModules = require("next-plugin-transpile-modules");
const withCustomBabelConfigFile = require("next-plugin-custom-babel-config");

module.exports = withCustomBabelConfigFile(
  withTranspileModules({
    transpileModules: ["@org/api-workspace"],
    babelConfigFile: path.resolve("../babel.config.js")
  })
);

Current Tags

  • 1.0.4                                ...           latest (6 months ago)

5 Versions

  • 1.0.4                                ...           6 months ago
  • 1.0.3                                ...           6 months ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 10
This Month 10
Last Day 0
Last Week 6
Last Month 8
Dependencies (0)
None
Dev Dependencies (1)