Skip to content

Commit

Permalink
feat(babel): add temporary solution to be able to load macros outside…
Browse files Browse the repository at this point in the history
… `process.cwd()`; see: kentcdodds/babel-plugin-macros#87
  • Loading branch information
Viktor Vincze committed Aug 7, 2019
1 parent f05c0e3 commit 873cef3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/configs/babel/root/plugins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import path from 'path'
import fs from 'fs'

import mhyConfig from '@/configs/mhy'

// Temporary ugly hack! Babel plugin macro can only resolve from process.cwd() as root.
// We just simply patching the sourcecode until there's a better option for this.
const macrosPluginPath = require.resolve('babel-plugin-macros')
fs.readFile(macrosPluginPath, 'utf8', function(err, data) {
fs.writeFile(
macrosPluginPath,
data.replace(
'return resolve.sync(source, {',
`return resolve.sync(source, {
paths: [p.resolve(__dirname, '../../'), p.resolve(process.cwd(), 'node_modules')],
`
),
'utf8',
() => {}
)
})

export default (defaults = []) => {
const r = [
...defaults,
Expand Down

0 comments on commit 873cef3

Please sign in to comment.