File tree Expand file tree Collapse file tree 6 files changed +73
-17
lines changed Expand file tree Collapse file tree 6 files changed +73
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
[ ENGLISH] ( ./README.md )
4
4
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 配合使用,也可以单独使用。
6
6
7
- 项目的代码大部分提取自 vuepress 项目,但进行了一系列修改、修正以及优化,以便它能在非 [ vuepress] ( https://github.com/vuejs/vuepress ) 项目中使用。在此对这一官方包的开发者们表示感谢。如果你有兴趣,可以前往该项目,并 star。
7
+ 项目的代码大部分提取自 [ vuepress] ( https://github.com/vuejs/vuepress ) 项目,但进行了一系列修改、修正以及优化,使它能在非 vuepress 项目中使用。在此对这一官方包的开发者们表示感谢。如果你有兴趣,可以前往该项目查看源码并 star。
8
8
9
9
![ screenshot] ( ./images/screenshot.png )
10
10
@@ -18,6 +18,8 @@ npm i @tianyong90/vue-markdown-loader -S
18
18
19
19
### 与 vue-loader 一起使用
20
20
21
+ 一般情况下,推荐与 vue-loader 一起使用。
22
+
21
23
1 . 配置
22
24
23
25
在 webpack.config.js 中为 .md 文件添加加载规则
@@ -59,7 +61,7 @@ module: {
59
61
60
62
2 . 将 ` .md ` 文件作为 vue 单文件组件导入
61
63
62
- ``` vue
64
+ ``` html
63
65
<template >
64
66
<Hello />
65
67
</template >
@@ -79,8 +81,72 @@ export default {
79
81
80
82
### 与 html-loader 一起使用
81
83
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
+
82
146
### 单独使用
83
147
148
+
149
+
84
150
## License
85
151
86
152
MIT
Original file line number Diff line number Diff line change 7
7
"dev" : " yarn run build && lerna run dev --stream --scope example" ,
8
8
"build" : " lerna run build --scope @tianyong90/vue-markdown-loader" ,
9
9
"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"
11
12
},
12
13
"husky" : {
13
14
"hooks" : {
Original file line number Diff line number Diff line change 16
16
"@tianyong90/vue-markdown-loader" : " ^0.1.1" ,
17
17
"babel-loader" : " ^8.0.5" ,
18
18
"babel-plugin-syntax-dynamic-import" : " ^6.18.0" ,
19
- "clean-webpack-plugin" : " ^3.0.0" ,
20
19
"css-loader" : " ^3.0.0" ,
21
20
"html-webpack-plugin" : " ^3.2.0" ,
22
21
"node-sass" : " ^4.11.0" ,
Original file line number Diff line number Diff line change 1
1
const webpack = require ( 'webpack' ) ;
2
2
const path = require ( 'path' ) ;
3
3
4
- const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
5
4
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
6
- const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' )
7
5
const VueLoaderPlugin = require ( 'vue-loader/lib/plugin' )
8
6
9
7
module . exports = {
@@ -105,7 +103,6 @@ module.exports = {
105
103
} ,
106
104
stats : 'minimal' ,
107
105
plugins : [
108
- new CleanWebpackPlugin ( ) ,
109
106
new HtmlWebpackPlugin ( {
110
107
title : '@tianyong90/vue-markdown-loader example' ,
111
108
filename : 'index.html' ,
Original file line number Diff line number Diff line change
1
+ cp ../README.md ../test.md
Original file line number Diff line number Diff line change 1790
1790
" @types/source-list-map" " *"
1791
1791
source-map "^0.6.1"
1792
1792
1793
- " @types/webpack@*" , "@types/webpack@^4.4.31" :
1793
+ " @types/webpack@* " :
1794
1794
version "4.39.1"
1795
1795
resolved "https://registry.npm.taobao.org/@types/webpack/download/@types/webpack-4.39.1.tgz#d76cd551cc851198f67f75ff3e26551d204530e9"
1796
1796
integrity sha1-12zVUcyFEZj2f3X/PiZVHSBFMOk=
@@ -3035,14 +3035,6 @@ clean-stack@^2.0.0:
3035
3035
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"
3036
3036
integrity sha1-7oRy27Ep5yezHooQpCfe6d/kAIs=
3037
3037
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
-
3046
3038
cli-boxes@^1.0.0 :
3047
3039
version "1.0.0"
3048
3040
resolved "https://registry.npm.taobao.org/cli-boxes/download/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143"
You can’t perform that action at this time.
0 commit comments