forked from egoist/tailwindcss-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
24 lines (17 loc) · 834 Bytes
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fs = require('fs')
const path = require('path')
const NORMALIZE_CSS = `_fs.default.readFileSync(require.resolve('normalize.css'), 'utf8')`
const PREFLIGHT = "_fs.default.readFileSync(`${__dirname}/css/preflight.css`, 'utf8')"
module.exports = async function (source) {
const done = this.async()
console.log(`Replacing code in ${this.resourcePath}`)
if (!source.includes(NORMALIZE_CSS)) {
return done(new Error(`Can't find the code that uses normalize.css`))
}
if (!source.includes(PREFLIGHT)) {
return done(new Error(`Can't find the code that uses preflight`))
}
source = source.replace(NORMALIZE_CSS, JSON.stringify(fs.readFileSync(require.resolve('normalize.css'), 'utf8')))
.replace(PREFLIGHT, JSON.stringify(fs.readFileSync(`${this.context}/css/preflight.css`, 'utf8')))
done(null, source)
}