package.json相關html
echo $LOGNAME
輸出環境變量 用$- 'test': '' //測試服務
- 'start': '' //啓動服務
- 'build': '' //編譯
- 'docs': '' //文檔的生成
- 'server:start': 'cross-env NODE_ENV=development supervisor ./app.js' 啓動服務
- 'server:dev': 'cross-env NODE_ENV=development gulp' //開發的後端 編譯後端
- 'server:prod': 'cross-env NODE_ENV=production gulp' //後端上線的js
- 'server:hint': 'cross-env NODE_ENV=hint gulp' //對js腳本進行校驗
- 'client:dev': webpack--mode development //開發的前端
- 'client:prod': webpack--mode production //前端的上線
複製代碼
檢查80端口是否衝突前端
base_port="80"
check_port= `lsof -i:${base_port} | awk '{print $2}'`
while ["$check_port" != ""]
do
let base_port=base_port+1
check_port= `lsof -i:${base_port}`
done
echo ${base_port}
複製代碼
shelljs包 用js 去書寫shell 開頭標註 #!/usr/bin/env nodenode
gulp相關 編譯serverwebpack
目標web
實現的相關包以及坑shell
參考npm
const gulp = require("gulp");
const gulp = require("gulp-babel");
const watch = require("gulp-watch");
const rollup = require("gulp-rollup");
const replace = require("rollup-plugin-replace");
const eslint = require("gulp-eslint");
const entry = "./src/server/**/*.js";
//須要清洗的代碼
const cleanEntry = "./src/server/config/index.js";
//開發環境
function builddev() {
return watch(entry, {
ignoreInitial: false
}, function() {
gulp.src(entry)
.pipe(babel({
//關閉外部的babelrc
babelrc: false,
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}))
.pipe(gulp.dest('dist'))
})
}
//上線環境
function buildprod() {
return gulp.src(entry)
.pipe(babel({
//關閉外部的babelrc
babelrc: false,
ignore: ["./src/server/config/*.js"],
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}))
.pipe(gulp.dest('dist'))
}
//清洗流
function buildconfig() {
return gulp.src(entry)
// transform the files here.
.pipe(rollup({
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
],
output: {
format: 'cjs'
}
input: cleanEntry
}))
.pipe(gulp.dest('./dist'))
}
//代碼校驗
function buildhint() {
return gulp.src(entry)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
let build = gulp.series(builddev)
if (process.env.NODE_ENV == "production") {
build = gulp.series(buildhint, buildprod, buildconfig)
}
if (process.env.NODE_ENV == "hint") {
build = gulp.series(buildhint)
}
gulp.task("default", build);
複製代碼
npm install webpack webpack-cli -g --save-devjson
配置webpack.config.jsgulp
const argv = require("yargs-parser")(process.env.slice(2));
const _mode = argv.mode || "development";
const _mergeConfig = require( `./config/webpack.${_mode}.js` );
const merge = require("webpack-merge");
const glob = require("glob");
const files = glob.sync("./src/web/views/**/*.entry.js");
for (let item of files) {
if (/.+\/([a-zA-Z]+-[a-zA-Z]+)(\.entry\.js$)/g.test(item) == true) {
const entryKey = RegExp.$1;
//html-plugin
//註冊插件 html-plugin 送到dist以前攔截 插入靜態資源
}
}
let _entry = {};
let webpackConfig = {
entry: _entry
};
module.exports = mrege(webpackConfig, _mergeConfig);
複製代碼
未完待續....後端