gozala / alias-quokka-plugin Goto Github PK
View Code? Open in Web Editor NEWQuokka plugin to provide module import aliases
License: MIT License
Quokka plugin to provide module import aliases
License: MIT License
I can't figure it out.
I'm trying to import project files from within a scratch file.
This is my global config (I don't understand if Quokka can use the alias here, just trying it out TBH):
{
"pro":true,
"plugins": ["alias-quokka-plugin"],
"alias": {
"@": "./src"
}
}
This is my project's package.json
:
"quokka": {
"babel": true,
"plugins": ["alias-quokka-plugin"],
"alias": {
"@": "./src"
}
}
I still get:
Quokka #1 (node: v8.11.1, plugins: alias-quokka-plugin)
Cannot find module '@/core/objects/errors'
What should I be doing?
Really surprised this isn't built in.
Hey @Gozala
I'd like to start work on and PR an update to add support to import aliases from external files.
These could be standalone files, or tsconfig.json
.
I'll add the correct to determine the alias, and handle arrays as well.
Sound good?
Alias HQ is a programmatic way to piggyback aliases already configured in tsconfig.json
:
As Quokka's config is JSON, it wouldn't be directly compatible, but is there some way to run it as a plugin or such like?
EDIT: looks like I might be able to get it working using babel's config
First of all, thanks for such an awesome plugin. It's really useful.
If I could wish for one thing, it would be support for Vue.js in a Webpack environment. I spent a good amount of time trying to get your plugin working with their setup (e.g. import "x" from "@/something/here"), but I had to give up eventually.
Am I missing something, or would it be possible for you to try to make an example with Vue?
If you tried the basic Webpack template via the Vue CLI (https://github.com/vuejs/vue-cli) with your plugin, I think you'd see what I'm getting at. :)
A simple example would be really helpful.
Thanks in advance.
Note: I tried rewriting your plugin to follow the way the Vue CLI Webpack template resolves aliases (found in webpack.base.conf.js), but it didn't work.
In my webpack setup I have the following alias:
'$route-views': resolve('src/route-views')
And in the package.json I have the following:
"quokka": {
"pro": true,
"babel" : true,
"plugins": ["alias-quokka-plugin"],
"alias": {
"@": "src",
"$c": "src/components",
"$route-views": "src/route-views/dashboards/goals",
In a javascript file, I'm importing a module under that folder as such:
import {getGrid} from '$route-views/dashboards/GoalsGridDates'
However, Quokka spits out this error:
Cannot find module '$route-views/dashboards/GoalsGridHelper'
at Function.Module._resolveFilename module.js:470
at Module._load module.js:418
at Function.Module._load.rest [as _load] .\node_modules\alias-quokka-plugin\src\main.js:13
I have a bunch of modules under @app, for example @app/api. alias-quokka-plugin
won't let me make an alias to @app, then find things under @app by traversing subdirectories.
Example:
I have few packages:
@app/api
@app/lib/interface/status
@app/lib/enums
@app/lib/controller/BaseFormController
I would like to do this and have this package traverse subdirectories by itself:
"quokka": {
"plugins": ["alias-quokka-plugin"],
"alias": {
"@app": "src/app"
}
},
However, I have to do it this way, which is troublesome:
"quokka": {
"plugins": ["alias-quokka-plugin"],
"alias": {
"@app/api": "src/app/api",
"@app/lib/interface/status": "src/app/lib/interface/status",
"@app/lib/enums": "src/app/lib/enums",
"@app/lib/controller/BaseFormController": "src/app/lib/controller/BaseFormController"
}
},
Can this be fixed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.