Skip to content

Commit 1d9ddd5

Browse files
committed
readme wip
1 parent 211000f commit 1d9ddd5

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

README-CN.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[ENGLISH](./README.md)
44

5-
这是一个 Webpack loader,用于加载 markdown 文件。通过适当的配置,可以将 markdown 文件内容转换为一 vue sfc 组件对象或者 html 内容,此外还可以直接转换为一个包含解析结果、frontmatter 等数据的对象因此,它可以很方便的与 vue-loader 或者 html-loader 配合使用,也可以单独使用。
5+
这是一个用于加载 markdown 文件的 Webpack loader。通过配置,可以将 markdown 文件内容转换为一 vue sfc 组件对象或者 html 内容,此外还可以直接转换为一个包含解析结果、frontmatter 等数据的对象因此,它可以很方便的与 vue-loader 或者 html-loader 配合使用,也可以单独使用。
66

7-
项目的代码大部分提取自 vuepress 项目,但进行了一系列修改、修正以及优化,以便它能在非 [vuepress](https://github.com/vuejs/vuepress) 项目中使用。在此对这一官方包的开发者们表示感谢。如果你有兴趣,可以前往该项目,并 star。
7+
项目的代码大部分提取自 [vuepress](https://github.com/vuejs/vuepress) 项目,但进行了一系列修改、修正以及优化,使它能在非 vuepress 项目中使用。在此对这一官方包的开发者们表示感谢。如果你有兴趣,可以前往该项目查看源码并 star。
88

99
![screenshot](./images/screenshot.png)
1010

@@ -18,6 +18,8 @@ npm i @tianyong90/vue-markdown-loader -S
1818

1919
### 与 vue-loader 一起使用
2020

21+
一般情况下,推荐与 vue-loader 一起使用。
22+
2123
1. 配置
2224

2325
在 webpack.config.js 中为 .md 文件添加加载规则
@@ -59,7 +61,7 @@ module: {
5961

6062
2.`.md` 文件作为 vue 单文件组件导入
6163

62-
```vue
64+
```html
6365
<template>
6466
<Hello />
6567
</template>
@@ -79,8 +81,72 @@ export default {
7981
8082
### 与 html-loader 一起使用
8183
84+
vue-markdown-loader 也可以解析 markdown 文件,并返回一个包含 html 字符串供 html-loader 加载。
85+
86+
1. 配置
87+
88+
在 webpack.config.js 中为 .md 文件添加加载规则
89+
90+
```js
91+
module: {
92+
rules: [
93+
{
94+
test: /\.vue$/,
95+
loader: 'vue-loader'
96+
},
97+
{
98+
test: /\.md$/,
99+
use: [
100+
{
101+
loader: 'vue-loader',
102+
options: {
103+
compilerOptions: {
104+
preserveWhiteSpace: false
105+
}
106+
}
107+
},
108+
{
109+
loader: '@tianyong90/vue-markdown-loader',
110+
options: {
111+
// sourceDir: ''
112+
contentCssClass: 'markdown-body',
113+
markdown: {
114+
lineNumbers: true, // 启用行号
115+
}
116+
}
117+
}
118+
]
119+
}
120+
]
121+
},
122+
// other options
123+
```
124+
125+
2. 将 `.md` 文件作为 vue 单文件组件导入
126+
127+
```html
128+
<template>
129+
<Hello />
130+
</template>
131+
132+
<script scoped>
133+
import Hello from 'hello.md'
134+
135+
export default {
136+
components: { Hello }
137+
}
138+
</script>
139+
140+
<style>
141+
// 为解析出来的 markdown 元素添加样式
142+
</style>
143+
```
144+
145+
82146
### 单独使用
83147
148+
149+
84150
## License
85151
86152
MIT

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "yarn run build && lerna run dev --stream --scope example",
88
"build": "lerna run build --scope @tianyong90/vue-markdown-loader",
99
"demo": "lerna run dev --scope example --stream -- --colors",
10-
"release": "yarn --pure-lockfile && node scripts/release.js"
10+
"release": "yarn --pure-lockfile && node scripts/release.js",
11+
"copy-readme": "bash scripts/copyreadme.sh"
1112
},
1213
"husky": {
1314
"hooks": {

packages/example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@tianyong90/vue-markdown-loader": "^0.1.1",
1717
"babel-loader": "^8.0.5",
1818
"babel-plugin-syntax-dynamic-import": "^6.18.0",
19-
"clean-webpack-plugin": "^3.0.0",
2019
"css-loader": "^3.0.0",
2120
"html-webpack-plugin": "^3.2.0",
2221
"node-sass": "^4.11.0",

packages/example/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const webpack = require('webpack');
22
const path = require('path');
33

4-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
54
const HtmlWebpackPlugin = require('html-webpack-plugin')
6-
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
75
const VueLoaderPlugin = require('vue-loader/lib/plugin')
86

97
module.exports = {
@@ -105,7 +103,6 @@ module.exports = {
105103
},
106104
stats: 'minimal',
107105
plugins: [
108-
new CleanWebpackPlugin(),
109106
new HtmlWebpackPlugin({
110107
title: '@tianyong90/vue-markdown-loader example',
111108
filename: 'index.html',

scripts/copyreadme.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cp ../README.md ../test.md

yarn.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@
17901790
"@types/source-list-map" "*"
17911791
source-map "^0.6.1"
17921792

1793-
"@types/webpack@*", "@types/webpack@^4.4.31":
1793+
"@types/webpack@*":
17941794
version "4.39.1"
17951795
resolved "https://registry.npm.taobao.org/@types/webpack/download/@types/webpack-4.39.1.tgz#d76cd551cc851198f67f75ff3e26551d204530e9"
17961796
integrity sha1-12zVUcyFEZj2f3X/PiZVHSBFMOk=
@@ -3035,14 +3035,6 @@ clean-stack@^2.0.0:
30353035
resolved "https://registry.npm.taobao.org/clean-stack/download/clean-stack-2.2.0.tgz?cache=0&sync_timestamp=1564586594378&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fclean-stack%2Fdownload%2Fclean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
30363036
integrity sha1-7oRy27Ep5yezHooQpCfe6d/kAIs=
30373037

3038-
clean-webpack-plugin@^3.0.0:
3039-
version "3.0.0"
3040-
resolved "https://registry.npm.taobao.org/clean-webpack-plugin/download/clean-webpack-plugin-3.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fclean-webpack-plugin%2Fdownload%2Fclean-webpack-plugin-3.0.0.tgz#a99d8ec34c1c628a4541567aa7b457446460c62b"
3041-
integrity sha1-qZ2Ow0wcYopFQVZ6p7RXRGRgxis=
3042-
dependencies:
3043-
"@types/webpack" "^4.4.31"
3044-
del "^4.1.1"
3045-
30463038
cli-boxes@^1.0.0:
30473039
version "1.0.0"
30483040
resolved "https://registry.npm.taobao.org/cli-boxes/download/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143"

0 commit comments

Comments
 (0)