Skip to content

Commit

Permalink
fix: add an example and make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Feb 23, 2019
1 parent 8bb074c commit 5798eb4
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-react"
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ build/
__output__/

.linaria-cache
.cache
14 changes: 14 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { styled } from 'linaria/react';

const Title = styled.h1`
font-family: sans-serif;
font-size: 16px;
`;

function App() {
return <Title>Hello world</Title>;
}

ReactDOM.render(<App />, document.getElementById('root'));
4 changes: 4 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<body>
<div id="root"></div>
<script src="./App.js"></script>
</body>
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"scripts": {
"test": "jest",
"example": "parcel example/index.html"
},
"dependencies": {
"parcel-bundler": "^1.11.0"
},
"devDependencies": {
"@babel/core": "^7.3.3",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"jest": "^24.1.0",
"linaria": "^1.1.4",
"parcel-assert-bundle-tree": "^1.0.0",
"source-map": "^0.7.3"
"parcel-plugin-linaria": "link:.",
"react": "^16.8.3",
"react-dom": "^16.8.3"
},
"peerDependencies": {
"linaria": "*"
},
"jest": {
"testEnvironment": "node",
Expand Down
30 changes: 18 additions & 12 deletions src/LinariaAsset.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const JSAsset = require('parcel-bundler/src/assets/JSAsset');
const { SourceMapConsumer } = require('source-map');
const transform = require('linaria/lib/transform');

const RESULT = Symbol('linaria-transform-result');

class LinariaAsset extends JSAsset {
constructor(...args) {
super(...args);
}

pretransform() {
const result = transform(this.contents, {
filename: this.name,
});
async pretransform() {
if (!/node_modules/.test(this.name)) {
const result = transform(this.contents, {
filename: this.name,
});

this[RESULT] = result;
this.contents = result.code;
this[RESULT] = result;
this.contents = result.code;
this.ast = null;
} else {
this[RESULT] = {};
}

super.pretransform();
await super.pretransform();
}

collectDependencies() {
Expand All @@ -38,6 +38,12 @@ class LinariaAsset extends JSAsset {

if (result.cssText) {
output.css = result.cssText;

if (this.options.sourceMaps) {
output.css += `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
result.cssSourceMapText || ''
).toString('base64')}*/`;
}
}

return output;
Expand Down
81 changes: 78 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,29 @@
"@babel/helper-get-function-arity" "^7.0.0"
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-react-display-name@^7.0.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.2.0.tgz#ebfaed87834ce8dc4279609a4f0c324c156e3eb0"
integrity sha512-Htf/tPa5haZvRMiNSQSFifK12gtr/8vwfr+A9y69uF0QcU77AVu4K7MiHEkTxF7lQoHOL0F9ErqgfNEAKgXj7A==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-react-jsx-self@^7.0.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.2.0.tgz#461e21ad9478f1031dd5e276108d027f1b5240ba"
integrity sha512-v6S5L/myicZEy+jr6ielB0OR8h+EH/1QFx/YJ7c7Ua+7lqsjj/vW6fD5FR9hB/6y7mGbfT4vAURn3xqBxsUcdg==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-jsx" "^7.2.0"

"@babel/plugin-transform-react-jsx-source@^7.0.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.2.0.tgz#20c8c60f0140f5dd3cd63418d452801cf3f7180f"
integrity sha512-A32OkKTp4i5U6aE88GwwcuV4HAprUgHcTq0sSafLxjr6AW0QahrCRCjxogkbbcdtpbXkuTOlgpjophCxb6sh5g==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-jsx" "^7.2.0"

"@babel/plugin-transform-react-jsx@^7.0.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.3.0.tgz#f2cab99026631c767e2745a5368b331cfe8f5290"
Expand Down Expand Up @@ -571,7 +594,7 @@
"@babel/helper-regex" "^7.0.0"
regexpu-core "^4.1.3"

"@babel/preset-env@^7.0.0":
"@babel/preset-env@^7.0.0", "@babel/preset-env@^7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.3.1.tgz#389e8ca6b17ae67aaf9a2111665030be923515db"
integrity sha512-FHKrD6Dxf30e8xgHQO0zJZpUPfVZg+Xwgz5/RdSWCbza9QLNk4Qbp40ctRoqDxml3O8RMzB1DU55SXeDG6PqHQ==
Expand Down Expand Up @@ -620,6 +643,17 @@
js-levenshtein "^1.1.3"
semver "^5.3.0"

"@babel/preset-react@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.0.0.tgz#e86b4b3d99433c7b3e9e91747e2653958bc6b3c0"
integrity sha512-oayxyPS4Zj+hF6Et11BwuBkmpgT/zMxyuZgFrMeZID6Hdh3dGlk4sHCAhdBCpuCKW2ppBfl2uCCetlrUIJRY3w==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-react-display-name" "^7.0.0"
"@babel/plugin-transform-react-jsx" "^7.0.0"
"@babel/plugin-transform-react-jsx-self" "^7.0.0"
"@babel/plugin-transform-react-jsx-source" "^7.0.0"

"@babel/register@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.0.0.tgz#fa634bae1bfa429f60615b754fc1f1d745edd827"
Expand Down Expand Up @@ -3955,7 +3989,7 @@ log-symbols@^2.2.0:
dependencies:
chalk "^2.0.1"

loose-envify@^1.0.0:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -4712,6 +4746,10 @@ parcel-bundler@^1.11.0:
v8-compile-cache "^2.0.0"
ws "^5.1.1"

"parcel-plugin-linaria@link:./.":
version "0.0.0"
uid ""

parse-asn1@^5.0.0:
version "5.1.4"
resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.4.tgz#37f6628f823fbdeb2273b4d540434a22f3ef1fcc"
Expand Down Expand Up @@ -5427,6 +5465,15 @@ prompts@^2.0.1:
kleur "^3.0.2"
sisteransi "^1.0.0"

prop-types@^15.6.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.8.1"

proto-list@~1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
Expand Down Expand Up @@ -5549,11 +5596,31 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-is@^16.8.3:
react-dom@^16.8.3:
version "16.8.3"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.3.tgz#ae236029e66210783ac81999d3015dfc475b9c32"
integrity sha512-ttMem9yJL4/lpItZAQ2NTFAbV7frotHk5DZEHXUOws2rMmrsvh1Na7ThGT0dTzUIl6pqTOi5tYREfL8AEna3lA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.3"

react-is@^16.8.1, react-is@^16.8.3:
version "16.8.3"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.3.tgz#4ad8b029c2a718fc0cfc746c8d4e1b7221e5387d"
integrity sha512-Y4rC1ZJmsxxkkPuMLwvKvlL1Zfpbcu+Bf4ZigkHup3v9EfdYhAlWAaVyA19olXq2o2mGn0w+dFKvk3pVVlYcIA==

react@^16.8.3:
version "16.8.3"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.3.tgz#c6f988a2ce895375de216edcfaedd6b9a76451d9"
integrity sha512-3UoSIsEq8yTJuSu0luO1QQWYbgGEILm+eJl2QN/VLDi7hL+EN18M3q3oVZwmVzzBJ3DkM7RMdRwBmZZ+b4IzSA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.3"

read-pkg-up@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-4.0.0.tgz#1b221c6088ba7799601c808f91161c66e58f8978"
Expand Down Expand Up @@ -5889,6 +5956,14 @@ sax@^1.2.4, sax@~1.2.1, sax@~1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

scheduler@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.3.tgz#bed3c5850f62ea9c716a4d781f9daeb9b2a58896"
integrity sha512-UxN5QRYWtpR1egNWzJcVLk8jlegxAugswQc984lD3kU7NuobsO37/sRfbpTdBjtnD5TBNFA2Q2oLV5+UmPSmEQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
Expand Down

0 comments on commit 5798eb4

Please sign in to comment.