Angular-cli: Using custom webpack loaders

Created on 19 Oct 2017  路  8Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [X ] feature request

Versions.

1.4.3

Desired functionality.

I have to load a custom loader to process .graphql files, I'd like to be able to add custom loaders to webpack config.

Mention any other details that might be useful.

The rule I want to add is

/* File loader for graphql files.
*  Returns file content as string
*/
  {
     test: /\.(graphql|gql)$/,
     exclude: /node_modules/,
     loader: 'graphql-tag/loader'
  }

Most helpful comment

@akeelnazir

I came around here, because I have the exact same use-case. I want to use the graphql-tag/loader but without the burden of ng eject. You can do this instead:

const myQuery = require('graphql-tag/loader!./myQuery.graphql');

All 8 comments

I know this is not the answer you wanted but truth is this has been extensively discussed before, and so this issue is a duplicate of https://github.com/angular/angular-cli/issues/1656. You can read there what the final word on that topic is for now.

@akeelnazir

I came around here, because I have the exact same use-case. I want to use the graphql-tag/loader but without the burden of ng eject. You can do this instead:

const myQuery = require('graphql-tag/loader!./myQuery.graphql');

@JohannesHoppe
How and where exactly would you use this 馃 ? Could you maybe give more explanation? Thanks!

The original poster obviously wants to import *.graphql files, for apollo. The usual way would be a configured webpack-loader. This is not possible with the angular-cli (exception: you ng eject the application). My require-statement does the same job and requires no changes to the webpack configuration. Cheers!

Hello! Thx, guys - needed to do this too - the require works fine, but wondering... is there currently a better supported way of doing this... i would very much like to just use import-statement.

Blocked by this issue, any updates in 2019???
@filipesilva

@hansl please be open, this made many developers drop Angular to choose React and Vue!!!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings