Giter Site home page Giter Site logo

Custom Babel config about mdx-go HOT 6 CLOSED

jxnblk avatar jxnblk commented on May 16, 2024
Custom Babel config

from mdx-go.

Comments (6)

jxnblk avatar jxnblk commented on May 16, 2024 4

Thanks! I don't think mdx-go should have its own config – it would add to the API surface area and this is really a babel configuration issue. With the changes from babel 6 to 7, supporting custom babel configs for all use-cases is very tricky, but I'd consider allowing the babel-loader to pick up custom configs for v7 only. Would need to test this out and make sure it works first

from mdx-go.

jxnblk avatar jxnblk commented on May 16, 2024

Currently the webpack babel-loader is set to babelrc: false to avoid unintentional conflicts. Have you tried with a custom webpack config? (Not sure if that would work right now, but it might)

from mdx-go.

juandc avatar juandc commented on May 16, 2024

My current solution is to copy and paste the necessary code from lib/config.js and modify as I need:

// webpack.config.js
const path = require('path');

const babel = {
  babelrc: false,
  presets: [
    [
      require.resolve('@babel/preset-env'),
      { modules: false }
    ],
    require.resolve('@babel/preset-react'),
  ],
  plugins: [
    require.resolve('@babel/plugin-proposal-class-properties'),
    require.resolve('@babel/plugin-proposal-export-default-from'),
    require.resolve('@babel/plugin-proposal-export-namespace-from'),
    require.resolve('@babel/plugin-transform-runtime'),
    require.resolve('@babel/plugin-syntax-dynamic-import'),
    require.resolve('styled-jsx/babel'), // this is all I need for styled-jsx
  ]
}

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: require.resolve('babel-loader'),
          options: babel
        }
      }
    ],
  },
  resolve: { // I tried babel-plugin-module-resolver but this way is easier
    alias: {
      'components': path.resolve('./src/components'),
      'utils': path.resolve('./src/utils'),
    },
  },
};

from mdx-go.

juandc avatar juandc commented on May 16, 2024

A better solution could be a mdx-go.config.js file with custom and "secure" configs. As well as Next.js with next.config.js: https://nextjs.org/docs#custom-configuration.

from mdx-go.

jxnblk avatar jxnblk commented on May 16, 2024

I just tested out a custom babel.config.js locally with styled-jsx and it seemed to work with the latest version... I'm wondering if you've run into a bug somewhere, so it'd be helpful if you could test this out on your end.

In my babel.config.js I have:

module.exports = {
  plugins: [
    'styled-jsx/babel'
  ]
}

Running [email protected] as a global install

from mdx-go.

jxnblk avatar jxnblk commented on May 16, 2024

Closing this out, but feel free to open a new issue if custom babel.config.js files aren't working

from mdx-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.