Удалены babel-plugin-nunjucks и lightningcss-loader
This commit is contained in:
@@ -1,70 +0,0 @@
|
|||||||
# babel-plugin-nunjucks
|
|
||||||
|
|
||||||
Плагин для [babel-loader](https://github.com/babel/babel-loader), позволяющий использовать шаблонизатор [Nunjucks](https://mozilla.github.io/nunjucks/) внутри JS-файлов.
|
|
||||||
|
|
||||||
## Установка
|
|
||||||
|
|
||||||
```bash
|
|
||||||
yarn add -D @advdominion/babel-plugin-nunjucks
|
|
||||||
```
|
|
||||||
|
|
||||||
## Использование
|
|
||||||
|
|
||||||
Используются [Tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) с тегом `njk`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
njk`
|
|
||||||
{% from "./item.njk" import item as item %}
|
|
||||||
|
|
||||||
<div class="items">
|
|
||||||
{% for n in range(0, 10) %}
|
|
||||||
{{item()}}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
```
|
|
||||||
|
|
||||||
Пример конфигурации Webpack:
|
|
||||||
|
|
||||||
```js
|
|
||||||
[
|
|
||||||
{
|
|
||||||
test: /\.js$/,
|
|
||||||
exclude: [/mocks\.js$/],
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'babel-loader',
|
|
||||||
options: {
|
|
||||||
cacheDirectory: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /mocks\.js$/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'babel-loader',
|
|
||||||
options: {
|
|
||||||
compact: false,
|
|
||||||
plugins: [
|
|
||||||
[
|
|
||||||
'@advdominion/babel-plugin-nunjucks',
|
|
||||||
{
|
|
||||||
templatesFolder: 'src/templates/',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
```
|
|
||||||
|
|
||||||
## Опции
|
|
||||||
|
|
||||||
- `templatesFolder` - строка, обязательный параметр. Путь до папки с файлами шаблонов
|
|
||||||
- `globals` - массив, необязательный параметр. Глобальные переменные для Nunjucks (например, `[{name: "message", value: "Hello, world!"}]`)
|
|
||||||
|
|
||||||
**Важно:** Параметр `cacheDirectory` в опциях babel-loader должен быть отключён.
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import nunjucks from 'nunjucks';
|
|
||||||
|
|
||||||
const babelPluginNunjucks = ({ types: t }) => {
|
|
||||||
return {
|
|
||||||
pre(state) {
|
|
||||||
const options = state.opts.plugins[0].options;
|
|
||||||
this.njkenv = new nunjucks.Environment(new nunjucks.FileSystemLoader(options.templatesFolder));
|
|
||||||
if (options.globals) {
|
|
||||||
for (const { name, value } of options.globals) {
|
|
||||||
this.njkenv.addGlobal(name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
visitor: {
|
|
||||||
TaggedTemplateExpression(path) {
|
|
||||||
if (path.get('tag').isIdentifier({ name: 'njk' })) {
|
|
||||||
const render = this.njkenv.renderString(path.node.quasi.quasis[0].value.raw);
|
|
||||||
path.replaceWith(t.stringLiteral(render));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default babelPluginNunjucks;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@advdominion/babel-plugin-nunjucks",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"main": "index.js",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://gitea.optiweb.ru/public/frontend.git"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@babel/core": "^8.0.0",
|
|
||||||
"nunjucks": "^3.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
# lightningcss-loader
|
|
||||||
|
|
||||||
[Lightning CSS](https://lightningcss.dev) loader for [Webpack](https://webpack.js.org)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { transform } from 'lightningcss';
|
|
||||||
|
|
||||||
return {
|
|
||||||
...,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: '@advdominion/lightningcss-loader',
|
|
||||||
options: {
|
|
||||||
implementation: transform,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
### Passing options to Lightning CSS
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { transform } from 'lightningcss';
|
|
||||||
|
|
||||||
return {
|
|
||||||
...,
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: '@advdominion/lightningcss-loader',
|
|
||||||
options: {
|
|
||||||
implementation: transform,
|
|
||||||
drafts: {
|
|
||||||
customMedia: true,
|
|
||||||
},
|
|
||||||
minify: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
```
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
const lightningcssLoader = function (source, sourceMap) {
|
|
||||||
const { implementation, ...options } = this.getOptions();
|
|
||||||
const callback = this.async();
|
|
||||||
|
|
||||||
if (typeof implementation !== 'function') {
|
|
||||||
throw new TypeError(
|
|
||||||
`[lightningcss-loader]: The "implementation" option is required and must provide "transform" function of the LightningCSS`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { code, map } = implementation({
|
|
||||||
filename: this.resourcePath,
|
|
||||||
code: Buffer.from(source),
|
|
||||||
sourceMap: this.sourceMap,
|
|
||||||
inputSourceMap: this.sourceMap && sourceMap ? JSON.stringify(sourceMap) : undefined,
|
|
||||||
...options,
|
|
||||||
});
|
|
||||||
|
|
||||||
callback(undefined, code.toString(), map && JSON.parse(map.toString()));
|
|
||||||
};
|
|
||||||
|
|
||||||
export default lightningcssLoader;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@advdominion/lightningcss-loader",
|
|
||||||
"version": "1.0.2",
|
|
||||||
"type": "module",
|
|
||||||
"main": "index.js",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://gitea.optiweb.ru/public/frontend.git"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user