|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@author : Caven Chen |
|
|
@author : Caven Chen |
|
|
@date : 2023-05-06 |
|
|
|
|
|
**/ |
|
|
**/ |
|
|
|
|
|
|
|
|
'use strict' |
|
|
'use strict' |
|
|
|
|
|
|
|
|
import startServer from './server.js' |
|
|
import startServer from './server.js' |
|
|
import inlineImage from 'esbuild-plugin-inline-image' |
|
|
import inlineImage from 'esbuild-plugin-inline-image' |
|
|
import { glsl } from 'esbuild-plugin-glsl' |
|
|
import { glsl } from 'esbuild-plugin-glsl' |
|
|
|
|
|
import chokidar from 'chokidar' |
|
|
|
|
|
import shell from 'shelljs' |
|
|
|
|
|
import chalk from 'chalk' |
|
|
|
|
|
|
|
|
const obfuscatorConfig = { |
|
|
const obfuscatorConfig = { |
|
|
compact: true, //压缩代码 |
|
|
compact: true, //压缩代码 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const packageJson = fse.readJsonSync('./package.json') |
|
|
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() { |
|
|
function getTime() { |
|
|
let now = new Date() |
|
|
let now = new Date() |
|
|
let m = now.getMonth() + 1 |
|
|
let m = now.getMonth() + 1 |
|
|
|
|
|
|
|
|
async function buildNamespace(options) { |
|
|
async function buildNamespace(options) { |
|
|
const bundle = await rollup({ |
|
|
const bundle = await rollup({ |
|
|
input: 'libs/index.js', |
|
|
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) => { |
|
|
onwarn: (message) => { |
|
|
// Ignore eval warnings in third-party code we don't have control over |
|
|
// Ignore eval warnings in third-party code we don't have control over |
|
|
if (message.code === 'EVAL' && /protobufjs/.test(message.loc.file)) { |
|
|
if (message.code === 'EVAL' && /protobufjs/.test(message.loc.file)) { |
|
|
|
|
|
|
|
|
const exportNamespace = ` |
|
|
const exportNamespace = ` |
|
|
export const __namespace = { |
|
|
export const __namespace = { |
|
|
Cesium: exports.Cesium, |
|
|
Cesium: exports.Cesium, |
|
|
Supercluster: exports.Supercluster |
|
|
|
|
|
|
|
|
Supercluster: exports.Supercluster, |
|
|
|
|
|
CryptoJS: exports.CryptoJS |
|
|
} |
|
|
} |
|
|
` |
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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( |
|
|
export const build = gulp.series( |
|
|
() => buildNamespace({ node: true }), |
|
|
() => buildNamespace({ node: true }), |
|
|
() => buildModules({ node: true }), |
|
|
() => buildModules({ node: true }), |
|
|
|
|
|
|
|
|
copyAssets |
|
|
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) |
|
|
export const server = gulp.series(startServer) |