Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MiniprogramTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢卓城
MiniprogramTemplate
Commits
23278ae7
Commit
23278ae7
authored
Mar 15, 2021
by
谢卓城
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增:1.gulp prod
parent
fa9bbe9a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
33 deletions
+43
-33
gulpfile.js
gulpfile.js
+43
-33
No files found.
gulpfile.js
View file @
23278ae7
...
...
@@ -11,18 +11,18 @@ const tap = require("gulp-tap");
const
path
=
require
(
"path"
);
const
notify
=
require
(
"gulp-notify"
);
const
yargs
=
require
(
"yargs"
);
const
fs
=
require
(
'fs'
);
const
fs
=
require
(
"fs"
);
const
srcPath
=
"./src/**"
;
const
distPath
=
"./dist/"
;
//存放variable和mixin的sass文件在被引用时直接导入,不引入dist目录中
const
DIRECTIMPORT
=
[
"/scss/"
,
"/font/"
];
const
onError
=
function
(
err
)
{
const
onError
=
function
(
err
)
{
notify
.
onError
({
title
:
"Gulp"
,
subtitle
:
"Failure!"
,
message
:
"Error: <%= error.message %>"
,
sound
:
"Beep"
sound
:
"Beep"
,
})(
err
);
this
.
emit
(
"end"
);
...
...
@@ -34,11 +34,11 @@ const jsFiles = [`${srcPath}/*.js`, `!${srcPath}/env/*.js`];
const
jsonFiles
=
[
`
${
srcPath
}
/*.json`
];
const
imageFiles
=
[
`
${
srcPath
}
/images/*.{png,jpeg,jpg,gif,ico}`
,
`
${
srcPath
}
/images/**/*.{png,jpeg,jpg,gif,ico}`
`
${
srcPath
}
/images/**/*.{png,jpeg,jpg,gif,ico}`
,
];
/* 清除dist目录 */
gulp
.
task
(
"clean"
,
done
=>
{
gulp
.
task
(
"clean"
,
(
done
)
=>
{
del
.
sync
([
"dist/**"
,
"!dist/miniprogram_npm"
]);
done
();
});
...
...
@@ -57,7 +57,7 @@ const js = () => {
};
gulp
.
task
(
js
);
const
envJs
=
env
=>
{
const
envJs
=
(
env
)
=>
{
return
()
=>
{
return
gulp
.
src
(
`./src/env/
${
env
}
.js`
)
...
...
@@ -80,12 +80,15 @@ gulp.task(json);
const
wxss
=
()
=>
{
return
gulp
.
src
([...
sassFiles
,
...
DIRECTIMPORT
.
map
(
item
=>
`!
${
srcPath
}
/
${
item
}
/*`
)],
{
since
:
gulp
.
lastRun
(
wxss
)
})
.
src
(
[...
sassFiles
,
...
DIRECTIMPORT
.
map
((
item
)
=>
`!
${
srcPath
}
/
${
item
}
/*`
)],
{
since
:
gulp
.
lastRun
(
wxss
),
}
)
.
pipe
(
plumber
({
errorHandler
:
onError
}))
.
pipe
(
tap
(
file
=>
{
tap
(
(
file
)
=>
{
const
filePath
=
path
.
dirname
(
file
.
path
);
// console.log("filepath", filePath);
file
.
contents
=
Buffer
.
from
(
...
...
@@ -94,7 +97,7 @@ const wxss = () => {
(
$1
,
$2
)
=>
{
// console.log("$1", $1);
// console.log("$2", $2);
return
DIRECTIMPORT
.
some
(
item
=>
{
return
DIRECTIMPORT
.
some
(
(
item
)
=>
{
return
$2
.
indexOf
(
item
)
>
-
1
;
})
?
$1
...
...
@@ -127,7 +130,7 @@ const img = () => {
};
gulp
.
task
(
img
);
const
newfile
=
done
=>
{
const
newfile
=
(
done
)
=>
{
yargs
.
example
(
"gulp new -p mypage"
,
"创建mypage的page目录"
)
.
example
(
"gulp new -c mycomponent"
,
"创建mycomponent的component目录"
)
...
...
@@ -141,30 +144,30 @@ const newfile = done => {
alias
:
"src"
,
describe
:
"模板"
,
type
:
"string"
,
default
:
"template"
default
:
"template"
,
},
p
:
{
alias
:
"page"
,
describe
:
"page名称"
,
type
:
"string"
type
:
"string"
,
},
c
:
{
alias
:
"component"
,
describe
:
"component名称"
,
type
:
"string"
type
:
"string"
,
},
t
:
{
alias
:
"template"
,
describe
:
"components里的模板"
,
type
:
"string"
type
:
"string"
,
},
i
:
{
alias
:
"index"
,
describe
:
"page、components生成的文件与文件夹名称一致"
,
type
:
"string"
}
type
:
"string"
,
}
,
})
.
fail
(
msg
=>
{
.
fail
(
(
msg
)
=>
{
done
();
console
.
error
(
"创建失败"
);
console
.
log
(
msg
);
...
...
@@ -177,7 +180,7 @@ const newfile = done => {
const
source
=
args
.
s
;
const
filePaths
=
{
p
:
"pages"
,
c
:
"components"
c
:
"components"
,
};
let
name
,
...
...
@@ -208,31 +211,31 @@ const newfile = done => {
}
if
(
type
==
"pages"
)
{
let
jsonPath
=
'./src/app.json'
;
fs
.
readFile
(
jsonPath
,
'utf8'
,
function
(
err
,
data
)
{
if
(
err
)
console
.
log
(
err
);
var
json
=
JSON
.
parse
(
data
);
//读取的值
let
jsonPath
=
"./src/app.json"
;
fs
.
readFile
(
jsonPath
,
"utf8"
,
function
(
err
,
data
)
{
if
(
err
)
console
.
log
(
err
);
var
json
=
JSON
.
parse
(
data
);
//读取的值
json
.
pages
.
push
(
`
${
type
}
/
${
name
}
/
${
name
}
`
);
//把数据读出来,然后进行修改
var
str
=
JSON
.
stringify
(
json
,
null
,
2
);
var
str
=
JSON
.
stringify
(
json
,
null
,
2
);
//console.log(str);
fs
.
writeFile
(
jsonPath
,
str
,
function
(
err
)
{
if
(
err
)
{
fs
.
writeFile
(
jsonPath
,
str
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
}
});
});
}
else
{
stream
=
stream
.
pipe
(
replace
(
'container'
,
`
${
name
}
-container`
));
}
else
{
stream
=
stream
.
pipe
(
replace
(
"container"
,
`
${
name
}
-container`
));
}
return
stream
.
pipe
(
gulp
.
dest
(
`src/
${
type
}
/
${
name
}
/`
));
};
gulp
.
task
(
"new"
,
newfile
);
gulp
.
task
(
"watch"
,
done
=>
{
gulp
.
task
(
"watch"
,
(
done
)
=>
{
const
watchSassFiles
=
[
...
sassFiles
,
...
DIRECTIMPORT
.
map
(
item
=>
`!
${
srcPath
}
/
${
item
}
/**/*`
)
...
DIRECTIMPORT
.
map
(
(
item
)
=>
`!
${
srcPath
}
/
${
item
}
/**/*`
),
];
gulp
.
watch
(
watchSassFiles
,
wxss
);
gulp
.
watch
(
jsFiles
,
js
);
...
...
@@ -249,6 +252,13 @@ gulp.task(
gulp
.
parallel
(
"wxml"
,
"js"
,
"json"
,
"wxss"
,
"img"
,
"prodEnv"
)
)
);
gulp
.
task
(
"prod"
,
gulp
.
series
(
"clean"
,
gulp
.
parallel
(
"wxml"
,
"js"
,
"json"
,
"wxss"
,
"img"
,
"prodEnv"
)
)
);
gulp
.
task
(
"dev"
,
gulp
.
series
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment