Skip to content

Add a .postcss test in enablePostCssLoader #592

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

Closed
innocenzi opened this issue Jun 19, 2019 · 3 comments · Fixed by #594
Closed

Add a .postcss test in enablePostCssLoader #592

innocenzi opened this issue Jun 19, 2019 · 3 comments · Fixed by #594
Labels
Feature New Feature HasPR

Comments

@innocenzi
Copy link

I'm not sure how to format this issue, but everything is explained in this ticket: vuejs/vetur#1330

Adding the following loader solves my issue:

.addLoader({
    test: /\.postcss$/,
    use: [
        'vue-style-loader',
        {
            loader: 'css-loader',
            options: { importLoaders: 1 }
        },
        'postcss-loader'
        ]
})

I don't think I should have to add this manually. This loader is related to both Vue and PostCSS, so maybe a new method would solve the problem.

@Lyrkan
Copy link
Collaborator

Lyrkan commented Jun 19, 2019

Hi @hawezo,

Instead of adding a loader could you try doing the following?

Encore.configureLoaderRule('css', loaderRule => {
    loaderRule.test = /\.(postcss|css)$/,
});

If that works we could eventually add it automatically when enablePostCssLoader() is called.

@innocenzi
Copy link
Author

.configureLoaderRule() seems to be working correctly:

I think automatically adding it would be a great solution, but the warning should probably be hidden in this case.

@Lyrkan
Copy link
Collaborator

Lyrkan commented Jun 19, 2019

Perfect :)

If we add it automatically calling configureLoaderRule() won't be needed so you won't get a warning either.

@Lyrkan Lyrkan added Feature New Feature good first issue Good for newcomers labels Jun 19, 2019
@Lyrkan Lyrkan added HasPR and removed good first issue Good for newcomers labels Jun 19, 2019
weaverryan added a commit that referenced this issue Aug 9, 2019
This PR was merged into the master branch.

Discussion
----------

Add support for .postcss files

This PR closes #592 by making the `.css` rule also process `.postcss` files when `Encore.enablePostCssLoader()` has been called.

It seems that it can be useful in a Vue.js context in order to have proper syntax highlighting in IDEs by using `lang="postcss"`, as explained on https://vue-loader-v14.vuejs.org/en/features/postcss.html:

> Since vue-loader handles PostCSS on its styles internally, you only need to apply postcss-loader to standalone CSS files. There's no need to specify lang="postcss" on a style block if there is a PostCSS config file in your project.
>
> Sometimes the user may want to use lang="postcss" only for syntax highlighting purposes.

Commits
-------

f42da34 Add support for .postcss files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature HasPR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants