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

Pass the filename option to compiler #74

Merged

Conversation

NE-SmallTown
Copy link
Contributor

Pass the filename option to compiler, so the compiler can get and pass it down in some cases like transformNode/preTransformNode/postTransformNode

@NE-SmallTown
Copy link
Contributor Author

@sodatea Would you mind take a look?

@NE-SmallTown
Copy link
Contributor Author

Is there anything I could help to move this forward?

@haoqunjiang
Copy link
Member

What's the usage of it?

@haoqunjiang
Copy link
Member

If it's for the purpose mentioned in this issue vuejs/vue-loader#1603
Then as Evan said, it's out of the scope of this package.

@NE-SmallTown
Copy link
Contributor Author

NE-SmallTown commented Nov 27, 2019

IMO this is not related to vuejs/vue-loader#1603 (because my attention here is not to parse script/style), I want to do something like below:

  {
        test: /\.vue$/,
        use: [
          {
            loader: 'vue-loader',
          }
        ],
        exclude: path.resolve(__dirname, 'xxx')
  },

  {
        test: /\.vue$/,
        use: [
          {
            loader: 'vue-loader',
            options: {
              compilerOptions: {
                modules: [
                  {
                    transformNode: el => {
                      ...

                      return el;
                    },
                  },
                ],
              },
            },
          }
        ],
       include: path.resolve(__dirname, 'xxx'),
 }

but you will find that it doesn't work, the compilerOptions will be adopted for all vue files, so I think the way of this PR is the only (correct)way I could imagine to do this

@haoqunjiang
Copy link
Member

Do you have a reproduction repository?

@haoqunjiang
Copy link
Member

Could possibly be a bug in vue-loader

@NE-SmallTown
Copy link
Contributor Author

Here is the repro: https://github.com/NE-SmallTown/vue-compiler-options-bug-repro , sorry have no time to dig into the src code of vue-loder

@haoqunjiang
Copy link
Member

haoqunjiang commented Nov 28, 2019

It's a bug in vue-loader/lib/plugin that it only checks for the first rule that matches .vue files.

Next time please raise an issue before creating a PR because it could be an XY Problem (See also https://coolshell.cn/articles/10804.html for the Chinese version)

@NE-SmallTown
Copy link
Contributor Author

NE-SmallTown commented Nov 28, 2019

Thanks for your response, but from my personal perspective, this is not a XY problem because this PR is not trying to fix the bug(but yes, you can "fix" it with this PR), its purpose is to make the compilerOptions.modules more flexible(the bug fix is just one part of the "flexible"), the misunderstanding of your focus move to XY problem may because I delete the beginning word 'if' in 'I want to do something like below:' during one edit

@haoqunjiang
Copy link
Member

What else use cases could this feature resolve?
BTW in your implementation, the filename option would be passed to the vue-template-compiler instance, methods in modules still could not get it.

@NE-SmallTown
Copy link
Contributor Author

What else use cases could this feature resolve?

For example, I want to generate some Identities based on the filename, BTW, there is no secure/privacy problem because compilerOptions is Opt-in.

BTW in your implementation, the filename option would be passed to the vue-template-compiler instance, methods in modules still could not get it.

I think it could because I test it locally and after that I create this PR, you can check it from this line, the options passed to preTransforms is from the parse function which received options from this PR.

@haoqunjiang
Copy link
Member

I think it could because I test it locally and after that I create this PR, you can check it from this line, the options passed to preTransforms is from the parse function which received options from this PR.

Thanks for the note.
It is supported, though not well documented.


I'm still struggling to find good use cases for this option.
Need some more time to think about it.

@haoqunjiang haoqunjiang reopened this Nov 28, 2019
@haoqunjiang
Copy link
Member

@znck any thoughts?

Copy link
Member

@haoqunjiang haoqunjiang left a comment

Choose a reason for hiding this comment

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

I'm approving this PR because:

  1. no explicit objections from team members in near 3 weeks;
  2. it is purely additive;
  3. it provides a workaround for a bug that might not be resolved very soon in vue-loader;

Further actionable items:

  1. Need to address the new filename field in vue-template-compiler type definitions;
  2. Need to provide similar functionalities in the new compiler-sfc package in Vue 3.

(Another reason I'm OK with this PR is that even if the current design later prove suboptimal, it'll be replaced by compiler-sfc in Vue 3 anyway so we can do the experiment in this package)

@haoqunjiang haoqunjiang merged commit 3dda72d into vuejs:master Dec 8, 2019
@vue-bot
Copy link

vue-bot commented Dec 8, 2019

Hey @NE-SmallTown, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

@NE-SmallTown
Copy link
Contributor Author

NE-SmallTown commented Dec 9, 2019

Thanks.

Need to address the new filename field in vue-template-compiler type definitions;

Did you mean the TemplateCompileOptions type definition? I find that the definitions have been existed in the both RADME.md and compilerTemplate.ts in the init commit of component-compiler-utils

Need to provide similar functionalities in the new compiler-sfc package in Vue 3.

Don't know this before, seems it's a "TODO" package, at least for compilerTemplate.ts, so I think currently maybe it's not a follow-up of this PR?

Another work I can imagine is to update the dependency version in vue-loader

@haoqunjiang
Copy link
Member

Yeah, not a follow up, just backlog.

@haoqunjiang
Copy link
Member

Ideally, the type definition in the vue-template-compiler package should be updated and exported and we just import that in this package to replace the definition here

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.

3 participants