Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Added js directory path alias #328

Merged
merged 4 commits into from
Oct 15, 2020

Conversation

slavarazum
Copy link

With @ alias for js folder, we can use absoulte path instead of relative.

Imports will be more clear:

-import JetLabel from './../../Jetstream/Label'
+import JetLabel from '@/Jetstream/Label'

Its standard practice from vue cli preset. Also, you can check out article https://laravel-news.com/laravel-mix-alias with example of implementation.

@driesvints driesvints changed the title Added js directory path alias [1.x] Added js directory path alias Oct 8, 2020
.webpackConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'resources/js/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be shortened to:

'@': path.resolve('resources/js'),

(That's what I've always done.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested, it works 👍
Pushed the update.

@claudiodekker
Copy link
Contributor

claudiodekker commented Oct 8, 2020

I personally do really like this, but I do have two concerns:

  • Aliasing to @ does cause issues with discovery in PHPStorm (and perhaps other editors?) There are workarounds for this, but this makes me doubt whether this is a bit too opinionated to be a default?
  • This file is shared with the Livewire stack as well. Are we sure this doesn't cause issues over there?

Regarding the file being shared, I already mentioned this earlier today on this issue, so splitting it might be the way forward anyway.

@claudiodekker
Copy link
Contributor

Additionally, it might make more sense to target v2 (master), as this is not really a bugfix, and even more importantly because there's newly added Inertia views there (see #298) that we'd otherwise need to create a separate PR for anyway.

@slavarazum
Copy link
Author

@claudiodekker This update haven't any breaking changes and doesn't force you to use alias.

P.S. I have successfully setup alias resolving in VSCode and PHPStrom

@driesvints
Copy link
Member

@claudiodekker the changes are only done to the stubs so it doesn't matter really. This would only apply to new apps. It's also nbd to update the new Inertia views of v2 so that's fine 🙂

@taylorotwell
Copy link
Member

Maybe we should break out the webpack stubs to be different for Inertia vs. Livewire? Also, any more thoughts on the PHP Storm issue? I don't use PHP Storm so can't really comment on that.

@slavarazum
Copy link
Author

Root directory alias might be useful for both presets. PHPStorm supports webpack.config detection with alias resolving.

@claudiodekker
Copy link
Contributor

claudiodekker commented Oct 11, 2020

@slavarazum Yes, that applies to webpack.config.js, but not to the webpack.mix.js that Laravel (Mix) uses & that is being changed here.

One way around it that I linked earlier is to create a webpack.config.js with the actual config (that PHPStorm can use) and then to import that config into the webpack.mix.js, but I don't see that being implemented here, hence this being an issue.

@taylorotwell
Copy link
Member

@claudiodekker @slavarazum where do we go from here? We probably need to solve this PHP Storm issue that @claudiodekker is raising.

@slavarazum
Copy link
Author

@taylorotwell Let me export webpack config to separate file as @claudiodekker described.

@taylorotwell taylorotwell merged commit 043dfaa into laravel:1.x Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants