-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
631b884
commit f78d3ac
Showing
9 changed files
with
140 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module "rollup-pluginutils" { | ||
declare export function createFilter( | ||
include?: string | string[], | ||
exclude?: string | string[] | ||
): Function; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
|
||
module.exports = require('./lib/rollup'); |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* @flow */ | ||
|
||
const { createFilter } = require('rollup-pluginutils'); | ||
const transform = require('./transform'); | ||
const slugify = require('./slugify'); | ||
|
||
/* :: | ||
type RollupPluginOptions = { | ||
include?: string | string[], | ||
exclude?: string | string[], | ||
sourceMap?: boolean, | ||
evaluate?: boolean, | ||
displayName?: boolean, | ||
} | ||
*/ | ||
|
||
module.exports = function linaria({ | ||
include, | ||
exclude, | ||
sourceMap, | ||
...rest | ||
} /* :RollupPluginOptions */ = {}) { | ||
const filter = createFilter(include, exclude); | ||
const cssLookup = {}; | ||
|
||
return { | ||
name: 'linaria', | ||
load(id /* :string */) { | ||
return cssLookup[id]; | ||
}, | ||
/* eslint-disable-next-line consistent-return */ | ||
resolveId(importee /* :string */) { | ||
if (importee in cssLookup) return importee; | ||
}, | ||
transform(code /* :string */, id /* :string */) { | ||
if (!filter(id)) return; | ||
|
||
const result = transform(id, code, rest); | ||
|
||
if (!result.cssText) return; | ||
|
||
let { cssText } = result; | ||
|
||
const slug = slugify(id); | ||
const filename = `${id.replace(/\.js$/, '')}_${slug}.css`; | ||
|
||
if (sourceMap && result.cssSourceMapText) { | ||
const map = Buffer.from(result.cssSourceMapText).toString('base64'); | ||
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`; | ||
} | ||
|
||
cssLookup[filename] = cssText; | ||
|
||
result.code += `\nimport ${JSON.stringify(filename)};\n`; | ||
|
||
/* eslint-disable-next-line consistent-return */ | ||
return result.code; | ||
}, | ||
}; | ||
}; |
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