Comments (13)
I read the npm page for babel-plugin-root-import
and it does basically what I proposed in my earlier comment. Thanks for pointing out that there is a package that does this too. The question that I had asked you regarding the rootPathPrefix
is answered by the documentation of the package in the config section. The default config
"plugins": [
[
"babel-plugin-root-import",
{
"rootPathSuffix": "./",
"rootPathPrefix": "~/"
}
]
],
is what I was looking for. I'm going to see if I want to incorporate this into my projects as a plugin or the solution I wrote myself.
from backpack.
Thanks, I'll test this later. It would be cool if there was an option to enable this automatically... Nuxt does this automatically for example. (see first comment)
from backpack.
Edit: I figured it out based on the example given and my own research.
module.exports = {
webpack: config => {
//point to the server index
config.entry.main = "./server/index.js"
//setup ~ alias to root source folder, can be accessed with ~/foo/bar
config.resolve = {
alias: {
"~": __dirname
}
}
//return extended config
return config
}
}
As long as your backpack.config.js
resides in the top level of your project this will allow you to reference the root folder as you would in a file being compiled by nuxt: import db from "~/server/db"
.
I propose the addition of this simple alias rule to the default backpack config since the tilde alias is a commonly used reference style.
from backpack.
Wondering the same
from backpack.
Just use the webpack config resolve entry
from backpack.
@walleXD Could you elaborate with an example?
from backpack.
Simple backpack.config.js file
const path = require('path')
const srcPath = path.resolve(process.cwd())
const aliases = {
'~~root': `${ srcPath }`
}
module.exports = {
webpack: (config, options, webpack) => {
config.resolve = {
alias: aliases
}
return config
}
}
from backpack.
This doesn't work for me though
from backpack.
This doesn't work for me though
What exactly does not work? What have your written in your config?
from backpack.
Simple example do work with eslint and build =)
Step 1: Install devdependecies
"babel-plugin-root-import": "^6.4.1",
"eslint-import-resolver-babel-plugin-root-import": "^1.1.1",
"eslint-plugin-import": "^2.18.2",
Step 2: add in .babelrc
in your project
"plugins": [
[
"babel-plugin-root-import",
{
"rootPathPrefix": "src",
"rootPathSuffix": "~"
}
]
]
Step 3: create file jsconfig.json
in root project
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"~/*": ["*"]
}
}
}
Step 4: In file .eslintrc
settings: {
'import/resolver': {
'babel-plugin-root-import': {
rootPathSuffix: '~'
}
}
}
`import controllers from '~/controllers';
from backpack.
@cassiolpaixao90 how do we use this if the root path is the root folder of the project? Do we use no rootPathPrefix
or rootPathPrefix: ""
?
from backpack.
Hey @douira, by default when use backpack the folder
src
isrootPathPrefix
in case should be rootPathPrefix="src" and can be any symbol rootPathSuffix="~| #| src..."
from backpack.
@douira see this example
https://github.com/cassiolpaixao90/example-backpack-alias
=) ?
from backpack.
Related Issues (20)
- [help] transpiling code from node_modules HOT 4
- Doesn't work with the latest version of Next.js HOT 2
- When release a new version to npm?
- Should config.resolve.modules be undefined when overriding backpack? HOT 3
- v0.8.0 Incompatible HOT 5
- Not work in node 10 HOT 1
- Update dependency around event-stream HOT 4
- Question regarding using it for monorepo
- Jest example not working HOT 3
- Live reload doesn't work inside docker HOT 2
- Specifying files and folders to ignore from watching
- await errors on Express route
- 不支持导出 HOT 1
- Documention on how to change environment. HOT 1
- Incorrect reference to source-map-support/register when using backpack in yarn workspaces HOT 5
- Any idea why I need a babel.config.js file and a .babelrc? HOT 1
- Add out of the box TypeScript support with @babel/preset-typescript HOT 2
- How to debug this project? HOT 3
- Backpack artifacts `source-map-support/register` not found in docker container HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backpack.