Skip to content

Commit bc71580

Browse files
committed
支持pug文件内的include指令所指向文件的原子类
1 parent 6d8ff56 commit bc71580

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

atomcss-loader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ module.exports = function(sSource) {
126126
// 没有找到 template 模板,则无需处理
127127
if (!sClassString) return sSource;
128128

129+
// 支持 pug 文件内 include 的文件的编译
130+
let pugFileList = sClassString.match(/include \S*\.pug/g) || [];
131+
pugFileList.forEach((file) => {
132+
let filePath = this.resourcePath.substr(0, this.resourcePath.lastIndexOf('/') + 1) + file.replace('include ', '');
133+
134+
// pug 文件改变,重新编译主文件
135+
this.addDependency(filePath)
136+
137+
let content = fs.readFileSync(filePath, 'utf-8')
138+
sClassString = sClassString.replace(file, content)
139+
})
140+
129141
let atomReg = new RegExp(sAtomRegExp, 'ig');
130142

131143
// 获取 pc 端原子类类名数组,并剔除重复的类名

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-atomcss-loader",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "",
55
"homepage": "https://github.com/wujr5/vue-atomcss-loader",
66
"repository": {

test/src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
div
33
h1.fsize-150.h-10.lh-10.bg-red test
44
HelloWorld
5+
include components/test.pug
56
</template>
67

78
<script>
9+
import '../../atomcss-common.css';
810
import HelloWorld from './components/HelloWorld.vue';
911
1012
export default {

test/src/components/HelloWorld.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class='hello fs-30'>
2+
<div class='hello fs-30 fw-600 bg-yellow'>
33
<h1>{{ msg }}</h1>
44
<p>
55
For a guide and recipes on how to configure / customize this project,<br>

test/src/components/test.pug

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div
2+
.h-100.lh-100.bg-red 这里是 pug
3+
.fs-20 pug pug pug

0 commit comments

Comments
 (0)