Bläddra i källkod

add dev mode

tags/3.2.0
Caven Chen 2 år sedan
förälder
incheckning
94be18c3ac
2 ändrade filer med 76 tillägg och 22 borttagningar
  1. 74
    22
      gulpfile.js
  2. 2
    0
      package.json

+ 74
- 22
gulpfile.js Visa fil

@@ -1,6 +1,5 @@
/**
@author : Caven Chen
@date : 2023-05-06
**/

'use strict'
@@ -21,6 +20,9 @@ import { babel } from '@rollup/plugin-babel'
import startServer from './server.js'
import inlineImage from 'esbuild-plugin-inline-image'
import { glsl } from 'esbuild-plugin-glsl'
import chokidar from 'chokidar'
import shell from 'shelljs'
import chalk from 'chalk'

const obfuscatorConfig = {
compact: true, //压缩代码
@@ -57,6 +59,26 @@ const buildConfig = {

const packageJson = fse.readJsonSync('./package.json')

const plugins = [
resolve({ preferBuiltins: true }),
commonjs(),
babel({
babelHelpers: 'runtime',
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['> 1%', 'last 2 versions', 'ie >= 10'],
},
},
],
],
plugins: ['@babel/plugin-transform-runtime'],
}),
]

function getTime() {
let now = new Date()
let m = now.getMonth() + 1
@@ -69,26 +91,7 @@ function getTime() {
async function buildNamespace(options) {
const bundle = await rollup({
input: 'libs/index.js',
plugins: [
commonjs(),
resolve({ preferBuiltins: true }),
babel({
babelHelpers: 'runtime',
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['> 1%', 'last 2 versions', 'ie >= 10'],
},
},
],
],
plugins: ['@babel/plugin-transform-runtime'],
}),
terser(),
],
plugins: [...plugins, ...[options.dev ? null : terser()]],
onwarn: (message) => {
// Ignore eval warnings in third-party code we don't have control over
if (message.code === 'EVAL' && /protobufjs/.test(message.loc.file)) {
@@ -158,7 +161,8 @@ async function buildModules(options) {
const exportNamespace = `
export const __namespace = {
Cesium: exports.Cesium,
Supercluster: exports.Supercluster
Supercluster: exports.Supercluster,
CryptoJS: exports.CryptoJS
}
`

@@ -319,6 +323,22 @@ async function deleteTempFile(options) {
}
}

async function regenerate(option, content) {
await fse.remove('dist/dc.min.js')
await fse.remove('dist/dc.min.css')
await fse.outputFile(path.join('dist', 'namespace.js'), content)
await buildModules(option)
await buildCSS()
await gulp
.src(['dist/modules.js', 'dist/namespace.js'])
.pipe(concat('dc.min.js'))
.pipe(gulp.dest('dist'))
.on('end', () => {
addCopyright(option)
deleteTempFile(option)
})
}

export const build = gulp.series(
() => buildNamespace({ node: true }),
() => buildModules({ node: true }),
@@ -357,4 +377,36 @@ export const buildRelease = gulp.series(
copyAssets
)

export const dev = gulp.series(
() => buildNamespace({ dev: true }),
copyAssets,
() => {
shell.echo(chalk.yellow('============= start dev =============='))
const watcher = chokidar.watch('src', {
persistent: true,
awaitWriteFinish: {
stabilityThreshold: 1000,
pollInterval: 100,
},
})
fse.readFile(path.join('dist', 'namespace.js'), 'utf8').then((content) => {
watcher
.on('ready', async () => {
await regenerate({ iife: true }, content)
await startServer()
})
.on('change', async () => {
let now = new Date()
await regenerate({ iife: true }, content)
shell.echo(
chalk.green(
`regenerate lib takes ${new Date().getTime() - now.getTime()} ms`
)
)
})
})
return watcher
}
)

export const server = gulp.series(startServer)

+ 2
- 0
package.json Visa fil

@@ -18,6 +18,7 @@
"type": "module",
"main": "dist/index.cjs",
"scripts": {
"dev": "rimraf dist && gulp dev",
"build": "rimraf dist && gulp build",
"build:node": "rimraf dist && gulp buildNode",
"build:iife": "rimraf dist && gulp buildIIFE",
@@ -39,6 +40,7 @@
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-terser": "^0.4.1",
"chalk": "^5.2.0",
"chokidar": "^3.5.3",
"esbuild": "^0.17.18",
"esbuild-plugin-glsl": "^1.2.1",
"esbuild-plugin-inline-image": "^0.0.9",

Laddar…
Avbryt
Spara