-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow interpolating components (#267)
* feat: allow interpolating components * WIP * support css tag * add composes support * Apply suggestions from code review Co-Authored-By: Jimmy Jia <tesrin@gmail.com> * Update src/utils/buildTaggedTemplate.js Co-Authored-By: Jimmy Jia <tesrin@gmail.com> * Update src/utils/buildTaggedTemplate.js Co-Authored-By: Jimmy Jia <tesrin@gmail.com>
- Loading branch information
Showing
16 changed files
with
698 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
module.exports = c => c; | ||
const cssLoader = require('css-loader'); | ||
const postcssLoader = require('postcss-loader'); | ||
const postcssNested = require('postcss-nested'); | ||
|
||
/** | ||
* A loader that replaces itself with css-loader and postcss-loader | ||
*/ | ||
module.exports.pitch = function pitch() { | ||
const remaining = this.loaders.slice(this.loaderIndex + 1); | ||
this.loaders = [ | ||
{ | ||
path: require.resolve('css-loader'), | ||
query: '', | ||
options: { | ||
...this.query, | ||
modules: true, | ||
importLoaders: remaining.length ? 2 : 1, | ||
}, | ||
}, | ||
{ | ||
path: require.resolve('postcss-loader'), | ||
query: '', | ||
options: { | ||
ident: 'postcss-astroturf', | ||
plugins: [require('postcss-nested')()], // eslint-disable-line global-require | ||
}, | ||
}, | ||
...remaining, | ||
]; | ||
function postcss(loader, css, map, meta, cb) { | ||
const ctx = { ...loader }; | ||
ctx.async = () => cb; | ||
ctx.loaderIndex++; | ||
ctx.query = { | ||
plugins: [postcssNested()], | ||
}; | ||
|
||
postcssLoader.call(ctx, css, map, meta); | ||
} | ||
|
||
module.exports = function loader(css, map, meta) { | ||
const done = this.async(); | ||
|
||
postcss(this, css, map, meta, (err, ...args) => { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
|
||
const ctx = { ...this }; | ||
ctx.query = { | ||
...this.query, | ||
modules: this.query.modules || true, | ||
importLoaders: 0, | ||
}; | ||
|
||
cssLoader.call(ctx, ...args); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.