Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[global,website] added info about css injections #1450

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tools/babel-plugin-styles/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function StylesPlugin({ types: t }, opts) {
}
}

function importProcessing(p, ident, cssPath) {
function importProcessing(p, ident, cssPath, usageScope = '@semcore') {
const code = fs
.readFileSync(cssPath)
.toString()
Expand All @@ -32,7 +32,7 @@ function StylesPlugin({ types: t }, opts) {
t.Identifier(ident),
t.TaggedTemplateExpression(
t.MemberExpression(
addNamed(p, 'sstyled', '@semcore/utils/lib/core/index'),
addNamed(p, 'sstyled', `${usageScope}/utils/lib/core/index`),
t.Identifier('insert'),
),
t.TemplateLiteral(
Expand Down Expand Up @@ -182,7 +182,8 @@ function StylesPlugin({ types: t }, opts) {
specifiers.forEach((specifier) => {
if (t.isImportDefaultSpecifier(specifier)) {
const cssPath = path.resolve(path.dirname(state.filename), source.value);
importProcessing(p, specifier.local.name, cssPath);
const usageScope = state.opts.scopeName;
importProcessing(p, specifier.local.name, cssPath, usageScope);
p.addComment('leading', `__reshadow-styles__:"${source.value}"`);
}
});
Expand Down
20 changes: 20 additions & 0 deletions website/docs/style/css-injection/css-injection-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ Add a new rule to your `webpack-config` :
}, ]
}
```
::: warning
For `intergalactic` we don't recomended to use it, but you could, if you add `scopeName` as a parameter to babel-plugin
:::
```javascript
{
test: /\.js$/,
include: /\/node_modules\/intergalactic\//, // <- set correct path
enforce: 'pre',
use: [{
loader: 'babel-loader',
options: {
plugins: [
['@semcore/babel-plugin-styles', {
scopeName: 'intergalactic' // <- add this
}]
],
},
}, ]
}
```

### Step three

Expand Down
Loading