Commit d56c563f authored by likely's avatar likely

step1

parent 4093645f
dist
node_modules
\ No newline at end of file
node_modules
.tmp
\ No newline at end of file
const path = require('path')
const gulp = require('gulp')
const gulpClean = require('gulp-clean')
const gulpLess = require('gulp-less')
const gulpRev = require('gulp-rev')
const gulpRevreplace = require('gulp-rev-replace')
const browserSync = require('browser-sync').create()
const runSequence = require('run-sequence')
const rollup = require('rollup')
const rollupCommonjs = require('rollup-plugin-commonjs')
const rollupNoderesolve = require('rollup-plugin-node-resolve')
const rollupBabel = require('rollup-plugin-babel')
const TuiaAutoUpload = require('tuia-auto-upload')
const pluginDir = './src/' // 插件库目录
const outputPath = './dist/'
const tmpPath = './.tmp/'
let pluginName
let pluginPath
......@@ -30,7 +37,7 @@ const rollupBundle = name => {
await bundle.write({
file: `${outputPath}${name}.js`,
format: 'umd',
format: 'iife',
sourcemap: true
})
}
......@@ -38,10 +45,28 @@ const rollupBundle = name => {
// clean bundle
gulp.task('bundle:clean', cb => {
return gulp.src(outputPath)
return gulp.src([outputPath, tmpPath])
.pipe(gulpClean())
})
// bundle vendor and plugin style
gulp.task('bundle:style', cb => {
return gulp.src([`${pluginPath}/*.less`])
.pipe(gulpLess())
.pipe(gulp.dest(outputPath))
})
// bundle statuc
gulp.task('bundle:static', cb => {
gulp.src([`${pluginPath}/index.html`])
.pipe(gulp.dest(outputPath))
gulp.src([`${pluginPath}/static/**`])
.pipe(gulp.dest(`${outputPath}static`))
cb()
})
// bundle vendor
gulp.task('bundle:vendor', rollupBundle('vendor'))
......@@ -55,12 +80,65 @@ gulp.task('bundle:init', ['bundle:clean'], cb => {
cb()
})
// bundle
gulp.task('bundle', ['bundle:init'], cb => {
runSequence(['bundle:style', 'bundle:static', 'bundle:vendor', 'bundle:plugin'], cb)
})
// bundle rev
gulp.task('bundle:rev', cb => {
return gulp.src([`${outputPath}**/*`, `!${outputPath}index.html`, `!${outputPath}/**/*.js.map`])
.pipe(gulpRev())
.pipe(gulp.dest(tmpPath))
.pipe(gulpRev.manifest('manifest.json'))
.pipe(gulp.dest(outputPath))
})
// bundle replace
gulp.task('bundle:replace', cb => {
const manifest = gulp.src(`${outputPath}manifest.json`)
const replace = gulpRevreplace({
manifest: manifest,
prefix: '//yun.tuisnake.com'
})
gulp.src([`${outputPath}index.html`])
.pipe(replace)
.pipe(gulp.dest(outputPath))
gulp.src([`${tmpPath}**/*.css`])
.pipe(replace)
.pipe(gulp.dest(tmpPath))
cb()
})
gulp.task('build:upload', cb => {
const uploader = new TuiaAutoUpload({
dir: path.join(__dirname, `${tmpPath}`),
originDir: '/jimu-web/plugin/'
})
uploader.start()
})
// preview plugin
gulp.task('preview', ['bundle:init'], cb => {
runSequence(['bundle:vendor', 'bundle:plugin'], cb)
gulp.task('preview', ['bundle'], cb => {
gulp.watch(`${pluginPath}/*.less`, ['bundle:style'])
gulp.watch(`${pluginPath}/vendor.js`, ['bundle:vendor'])
gulp.watch(`${pluginPath}/plugin.js`, ['bundle:plugin'])
browserSync.init({
watch: true,
server: {
baseDir: outputPath
}
})
cb()
})
// build plugin
gulp.task('build', [], cb => {
gulp.task('build', ['bundle'], cb => {
runSequence(['bundle:rev'], ['bundle:replace'], ['build:upload'], cb)
})
\ No newline at end of file
<html>
<head>
<title>插件预览页</title>
<link rel="stylesheet" type="text/css" href="/vendor.css">
<link rel="stylesheet" type="text/css" href="/plugin.css">
</head>
<body>
<div class="app"></div>
<script href="/vendor.js"></script>
<script href="/plugin.js"></script>
<script src="/vendor.js"></script>
<script src="/plugin.js"></script>
</body>
</html>
\ No newline at end of file
$('.app').html('这是一个测试插件')
\ No newline at end of file
$('.app').html('这是一个测试插件')
p {
font-size: 20px;
}
\ No newline at end of file
import $ from 'jquery'
\ No newline at end of file
import $ from 'jquery'
window.$ = $
console.log(1)
\ No newline at end of file
body{
background-color: #ff8406;
background-image: url('/static/demo.jpg');
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment