| 4 | * This loader tries to load an `app.scss` or and `app.css` relative to the main entry |
| 5 | */ |
| 6 | export default function loader(content: string, map: any) { |
| 7 | const { platform } = this.getOptions(); |
| 8 | const callback = this.async(); |
| 9 | const resolve = this.getResolve({ |
| 10 | extensions: [`.${platform}.scss`, `.${platform}.css`, '.scss', '.css'], |
| 11 | }); |
| 12 | |
| 13 | resolve(this.context, './app', (err, res) => { |
| 14 | if (err || !res) { |
| 15 | // if we ran into an error or there's no css file found, we just return |
| 16 | // original content and not append any additional imports. |
| 17 | return callback(null, content, map); |
| 18 | } |
| 19 | |
| 20 | const code = dedent` |
| 21 | // Added by app-css-loader |
| 22 | import "./${basename(res)}"; |
| 23 | ${content} |
| 24 | `; |
| 25 | |
| 26 | callback(null, code, map); |
| 27 | }); |
| 28 | } |