# san-anode-loader

> 一个将san单文件组件中的template编译为anode或apack的loader

Latest version **0.3.2** (published 2021-07-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install san-anode-loader
pnpm add san-anode-loader
yarn add san-anode-loader
bun add san-anode-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2021-07-06 |
| First published | 2021-06-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 26 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | baidu |
| Maintainers | vanishcode |
| Keywords | san, webpack, san-loader |

## Links

- npm: https://www.npmjs.com/package/san-anode-loader
- npm.io page: https://npm.io/package/san-anode-loader

## Dependencies (26)

- [ava](https://npm.io/package/ava.md) ^3.15.0
- [pug](https://npm.io/package/pug.md) ^3.0.2
- [san](https://npm.io/package/san.md) ^3.10.5
- [eslint](https://npm.io/package/eslint.md) ^7.29.0
- [webpack](https://npm.io/package/webpack.md) ^4.46.0
- [prettier](https://npm.io/package/prettier.md) ^2.3.2
- [san-loader](https://npm.io/package/san-loader.md) ^0.2.1
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.12.10
- [html-loader](https://npm.io/package/html-loader.md) ^1.1.2
- [@babel/types](https://npm.io/package/@babel/types.md) 7.12.12
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^11.0.0-beta.2
- [babel-loader](https://npm.io/package/babel-loader.md) ^8.2.2
- [loader-utils](https://npm.io/package/loader-utils.md) ^2.0.0
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.12.11
- [san-hot-loader](https://npm.io/package/san-hot-loader.md) ^0.1.2
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) 7.12.12
- [san-anode-utils](https://npm.io/package/san-anode-utils.md) ^3.10.0
- [@babel/generator](https://npm.io/package/@babel/generator.md) ^7.12.11
- [pug-plain-loader](https://npm.io/package/pug-plain-loader.md) ^1.1.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.12.11
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.23.4
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^8.3.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^3.4.0
- [@babel/plugin-syntax-class-properties](https://npm.io/package/@babel/plugin-syntax-class-properties.md) ^7.12.1
- [@webpack-contrib/eslint-config-webpack](https://npm.io/package/@webpack-contrib/eslint-config-webpack.md) ^3.0.0
- [@babel/plugin-proposal-class-properties](https://npm.io/package/@babel/plugin-proposal-class-properties.md) ^7.14.5

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2021-07-06
- 0.3.1 — 2021-07-06
- 0.3.0 — 2021-07-06
- 0.2.0 — 2021-07-05
- 0.1.1 — 2021-06-29
- 0.1.0 — 2021-06-29

## README

# san-anode-loader

`san-anode-loader` 是一个可以将 san 单文件组件或js中的模版部分编译为 aPack 或 aNode 形式的 webpack loader

合并了此项目：<https://github.com/luoyimaid/san-template-loader>

## 安装

使用 npm:

```bash
npm i san-anode-loader
```

使用 yarn:

```bash
yarn add san-anode-loader
```

## 使用

examples 中编写了一个最简单的、完整的项目示例。

下面是配置文件：

```js
{
    test: /\.pug$/,
    use: [
        {
            loader: "html-loader",
        },
        {
            loader: 'san-anode-loader',
            options: {
                compileTemplate: "aNode",
            },
        },
        {
            loader: "pug-plain-loader",
        },
    ],
},
{
    test: /\.html$/,
    use: [
        {
            loader: "html-loader",
            options: {
                esModule: false,
                minimize: false,
            },
        },
        {
            loader: 'san-anode-loader',
            options: {
                compileTemplate: "aPack",
            },
        },
    ],
},
{
    test: /\.js$/,
    use: [
        {
            loader: 'babel-loader',
            options: {
                plugins: [
                    require.resolve(
                        '@babel/plugin-proposal-class-properties'
                    ),
                    require.resolve(
                        'san-hot-loader/lib/babel-plugin'
                    ),
                ],
                presets: [
                    [
                        require.resolve('@babel/preset-env'),
                        {
                            targets: {
                                browsers: '> 1%, last 2 versions',
                            },
                            modules: false,
                        },
                    ],
                ],
            },
        },
        {
            loader: 'san-anode-loader',
            options: {
                compileTemplate: 'aPack',
                mode: 'compact',
            },
        },
    ],
},
```

### 处理单文件组件

当使用如 pug 类的 html 模版时，确保先走模板的 loader 然后再走 san-anode-loader，因为 san-loader 不能编译不是标准 html 的代码片段。

### 处理 js 中的template

mode代表模式：

- 严格模式 strict

- 兼容模式 compact

严格模式下，template 不可以出现字符串表达式，否则会报错，兼容模式下，会跳过有字符串表达式的 template

## 注意事项

目前兼容到 webpack5，但因为 html-loader2 有兼容性问题，所以同样的项目配置在 5 中会有问题，请移步 [html-loader](https://github.com/webpack-contrib/html-loader) 讨论区

## 问题反馈

可移步 [san discussion](https://github.com/baidu/san/discussions) 讨论区

## License

MIT &copy; [vanishcode](https://github.com/vanishcode)

MIT &copy; [luoyimaid](https://github.com/luoyimaid)

---
_Source: https://npm.io/package/san-anode-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
