How to load a raw text file in ionic 2 with webpack


I’ve added the raw-loader and the following to my webpack config:
{ test: /\.txt$/, loader: 'raw', }
And this to my js:
import {exercices} from 'data/exercices.txt';
But no matter where I put the file it says it can’t be found.
Module build failed: Error: Cannot resolve module 'exercices.txt' in /Users/...
It seems to be trying to find it in the same folder as the rest of the content for that page (js, css, html) etc. nested in the app folder.
The 3 problems with that are that that’s not where I want to keep the data file, even if I do put it there it still can’t find it, and it’s still not moving it to the www folder.

I tried removing the loader and just using Node’s require but Webpack insists on sticking its fingers in and complaining when it finds the require but not the file.


I got it working by changing the require to ./exercises.txt and putting it in the same folder as the page.
And I was able to put it in a data folder just inside the app folder by requiring ../../data/exercises.txt.
Of course misspelling exercises might have had something to do with it.
Rookie mistakes all around. :blush: