Code Monkey home page Code Monkey logo

babel-alias-quokka-plugin's Introduction

babel-alias-quokka-plugin

Quokka plugin to enable babel aliases that have been loaded with babel-plugin-module-resolver.

(these are not required, though, and aliases can be defined at the quokka.alias path of package.json.)

It uses babel-load-config to find the babel config. It then uses it to configure a module resolver from babel-plugin-module-resolver and uses that to resolve modules for Quokka.

Installation:

yarn add babel-alias-quokka-plugin

Then ensure this is in the top level of your package.json

"quokka": {
    "babel": true, // needed for imports
    "plugins": ["babel-alias-quokka-plugin"],
}

Aliases can either be pulled out of the configuration of babel-plugin-module-resolver automatically or you can specify them in package.json (see below)

Example Usages

Via Babel config:

{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["./"],
        "alias": {
          "test": "./test"
        }
      }
    ]
  ]
}

Via package.json:

  "quokka": {
    "babel": true,
    "plugins": ["babel-alias-quokka-plugin"],
    "alias": {
      "test": "./test"
    }
  }

Testing

To test, open test/index.js in VSCode and start Quokka

babel-alias-quokka-plugin's People

Contributors

timhuff avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

babel-alias-quokka-plugin's Issues

​​Cannot read property 'cwd' of undefined​​

Quokka config

Global, in ~/.quokka/config.json:

{
  "pro":true,
  "babel": true,  
  "plugins": ["babel-alias-quokka-plugin"]
}

Input

import { isArray } from "core/utils"

isArray([]) 

Output

​​​​Quokka #1 (node: v8.11.2, babel: v6.26.3, plugins: babel-alias-quokka-plugin)​​​​
​​​​
​​Cannot read property 'cwd' of undefined​​
  at ​​​resolvePath​​​ ​/Users/kyle/node_modules/babel-plugin-module-resolver/lib/resolvePath.js:107​
  at ​​​Function._module2.Module._load​​​ ​/Users/kyle/node_modules/babel-alias-quokka-plugin/bin.js:24​
  at ​​​Module.require​​​ ​module.js:596​
  at ​​​require​​​ ​internal/module.js:11​

Unexpected string

I'm trying to set this up in a project generated by @vue/cli 3.x, which sets up a webpack alias to map @ to ./src/. I've installed babel-alias-quokka-plugin into ~/.quokka, and I added the following to package.json in my project:

"quokka": {
    "babel": true
  },
  "babel": {
    "presets": [
      "@vue/app"
    ]
  }

Note that vue cli actually puts the babel config into babel.config.js by default, but the docs for quokka only mention .babelrc, so I tried adding it to package.json too.

Then if I start quokka I get a complain about @babel/register missing, so I installed that into my projects.

Then when I try to start quokka in a file that uses the @ alias, I get the following error:

​​​​Quokka 'utils.spec.js' (node: v11.7.0, babel: v7.2.2)​​​​
 
Unexpected string 
  at ​​​new Script​​​ ​vm.js:84​
  at ​​​createScript​​​ ​vm.js:264​
  at ​​​Object.runInThisContext​​​ ​vm.js:312​
  at ​​​Module._compile​​​ ​internal/modules/cjs/loader.js:684​

It should be noted that I'm getting this error in a normal js file, not a .vue single file component.

Any help would be greatly appreciated!

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.