Skip to content

Commit d1f09b0

Browse files
committed
add demo for native MP
1 parent 68eaa8a commit d1f09b0

33 files changed

+34912
-0
lines changed

examples/native/.eslintrc.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Eslint config file
3+
* Documentation: https://eslint.org/docs/user-guide/configuring/
4+
* Install the Eslint extension before using this feature.
5+
*/
6+
module.exports = {
7+
env: {
8+
es6: true,
9+
browser: true,
10+
node: true,
11+
},
12+
ecmaFeatures: {
13+
modules: true,
14+
},
15+
parserOptions: {
16+
ecmaVersion: 2018,
17+
sourceType: 'module',
18+
},
19+
globals: {
20+
wx: true,
21+
App: true,
22+
Page: true,
23+
getCurrentPages: true,
24+
getApp: true,
25+
Component: true,
26+
requirePlugin: true,
27+
requireMiniProgram: true,
28+
},
29+
// extends: 'eslint:recommended',
30+
rules: {},
31+
}

examples/native/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dist/
2+
node_modules/
3+
.DS_Store
4+
.idea
5+
src/**/*.js
6+
miniprogram_npm/
7+
.vscode
8+
demo*

examples/native/gulp.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
outDir: 'dist',
3+
style: {
4+
src: [
5+
'src/**/*.wxss'
6+
]
7+
},
8+
template: {
9+
src: 'src/**/*.wxml',
10+
},
11+
other: {
12+
src: [
13+
'miniprogram_npm{,/**}',
14+
'src/**',
15+
'!src/**/*.wxml',
16+
'!src/**/*.wxss',
17+
]
18+
}
19+
}

examples/native/gulpfile.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
const gulp = require('gulp')
2+
const clean = require('gulp-clean')
3+
const changed = require('gulp-changed')
4+
const change = require('gulp-change')
5+
const config = require('./gulp.config')
6+
const sourcemaps = require('gulp-sourcemaps')
7+
const { handleSource } = require('@dcasia/mini-program-tailwind-webpack-plugin/dist/universal-handler')
8+
const { Processor } = require('windicss/lib')
9+
const { HTMLParser } = require('windicss/utils/parser')
10+
const through2 = require('through2')
11+
const fs = require('fs')
12+
const windiConfig = require('./windi.config.js')
13+
14+
const outDir = config.outDir
15+
const styleSrc = config.style.src
16+
const templateSrc = config.template.src
17+
const otherSrc = config.other.src
18+
19+
const processor = new Processor(windiConfig)
20+
21+
gulp.task('handle:style', () =>
22+
gulp.src(
23+
styleSrc,
24+
{
25+
since: gulp.lastRun('handle:style')
26+
}
27+
)
28+
.pipe(sourcemaps.init())
29+
.pipe(change(content => {
30+
return handleSource('style', content, {enableRpx: true})
31+
}))
32+
.pipe(sourcemaps.write())
33+
.pipe(gulp.dest(outDir))
34+
)
35+
36+
gulp.task('handle:template',
37+
gulp.series(
38+
() => gulp.src(templateSrc)
39+
.pipe(changed(outDir))
40+
.pipe(change((content) => {
41+
42+
return handleSource('template', content)
43+
44+
}))
45+
.pipe(gulp.dest(outDir)),
46+
() => gulp.src(templateSrc)
47+
.pipe(through2.obj(function(file, enc, cb) {
48+
let result = ''
49+
if (file.isBuffer()) {
50+
const wxmlContent = file.contents.toString()
51+
const content = new HTMLParser(wxmlContent)
52+
.parseClasses()
53+
.map(i => i.result)
54+
.join(' ')
55+
const interpretedSheet = processor.interpret(content, true).styleSheet
56+
const MINIFY = true
57+
const styles = interpretedSheet.build(MINIFY)
58+
59+
result = handleSource('style', styles, {enableRpx: true})
60+
61+
}
62+
cb(null, result)
63+
}))
64+
.pipe(fs.createWriteStream('./dist/windi.wxss', {'flags': 'a'}))
65+
)
66+
)
67+
68+
gulp.task('handle:other', () =>
69+
gulp.src(otherSrc)
70+
.pipe(changed(outDir))
71+
.pipe(gulp.dest(outDir))
72+
)
73+
74+
gulp.task('watch:style', () => {
75+
gulp.watch(
76+
styleSrc,
77+
gulp.series('handle:style')
78+
)
79+
})
80+
81+
gulp.task('watch:template', () => {
82+
gulp.watch(
83+
templateSrc,
84+
gulp.series('handle:template')
85+
)
86+
})
87+
88+
gulp.task('watch:other', () => {
89+
gulp.watch(
90+
otherSrc,
91+
gulp.series('handle:other')
92+
)
93+
})
94+
95+
gulp.task(
96+
'watch',
97+
gulp.parallel(
98+
'watch:style',
99+
'watch:template',
100+
'watch:other'
101+
)
102+
)
103+
104+
gulp.task('clean', () =>
105+
gulp.src(
106+
[
107+
'dist',
108+
'./src/windi.wxss'
109+
],
110+
{
111+
allowEmpty: true
112+
}
113+
)
114+
.pipe(clean())
115+
)
116+
117+
gulp.task(
118+
'default',
119+
gulp.series(
120+
'clean',
121+
gulp.parallel(
122+
'handle:style',
123+
'handle:template',
124+
),
125+
'handle:other',
126+
'watch'
127+
)
128+
)

0 commit comments

Comments
 (0)