Skip to content

Commit

Permalink
fix(styles): fix CSS injector
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed Mar 13, 2020
1 parent 55007d1 commit f4ccef4
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 140 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@rollup/plugin-commonjs": "^11",
"@rollup/plugin-json": "^4",
"@rollup/plugin-node-resolve": "^7",
"@rollup/plugin-replace": "^2",
"@types/cssnano": "^4",
"@types/fs-extra": "^8",
"@types/icss-utils": "^4",
Expand Down Expand Up @@ -80,7 +81,7 @@
"rimraf": "^3",
"rollup": "^2",
"rollup-plugin-auto-external": "^2",
"rollup-plugin-terser": "^5",
"rollup-plugin-copy": "^3",
"sass": "^1",
"stylus": "^0.54",
"sugarss": "^2",
Expand Down
5 changes: 5 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import autoExternal from "rollup-plugin-auto-external";
import copy from "rollup-plugin-copy";
import ts from "@wessberg/rollup-plugin-ts";
import pkg from "./package.json";

import { dirname } from "path";
export default {
external: ["postcss"],
input: "src/index.ts",
Expand All @@ -14,12 +17,14 @@ export default {
],
plugins: [
json(),
replace({ "process.env.ROLLUP_POSTCSS_TEST": false }),
resolve({
preferBuiltins: true,
extensions: [".ts", ".mjs", ".js", ".json"],
}),
commonjs(),
autoExternal(),
copy({ targets: [{ src: "runtime", dest: dirname(pkg.main) }] }),
ts({ transpiler: "babel" }),
],
};
4 changes: 4 additions & 0 deletions runtime/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
env: { node: false, browser: true },
rules: { "prefer-const": "error" },
};
7 changes: 3 additions & 4 deletions src/runtime/inject-css.js → runtime/inject-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const styleTags = [];
*/
export default (css, options = {}) => {
if (!css || typeof document === "undefined") return;
const singleTag = typeof options.singeTag !== "undefined" ? options.singleTag : false;
const container = typeof options.container !== "undefined" ? options.container : document.head;
const position = options.prepend === true ? "prepend" : "append";

const createStyleTag = () => {
const styleTag = document.createElement("style");
Expand All @@ -25,10 +28,6 @@ export default (css, options = {}) => {
return styleTag;
};

const singleTag = typeof options.singeTag !== "undefined" ? options.singleTag : false;
const container = typeof options.container !== "undefined" ? options.container : document.head;
const position = options.prepend === true ? "prepend" : "append";

/** @type {HTMLStyleElement} */
let styleTag;

Expand Down
4 changes: 3 additions & 1 deletion src/loaders/postcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ const loader: Loader<PostCSSLoaderOptions> = {
const injectorName = safeId("injector");
const injectorPath = normalizePath(
await resolveAsync("./inject-css", {
basedir: path.join(__dirname, "..", "..", "runtime"),
basedir: process.env.ROLLUP_POSTCSS_TEST
? path.join(process.cwd(), "runtime")
: path.join(__dirname, "runtime"),
}),
);
const injectorData =
Expand Down
7 changes: 0 additions & 7 deletions src/runtime/.eslintrc.js

This file was deleted.

0 comments on commit f4ccef4

Please sign in to comment.