|
|
|
@@ -9,21 +9,17 @@ import path from 'path' |
|
|
|
import gulp from 'gulp' |
|
|
|
import esbuild from 'esbuild' |
|
|
|
import concat from 'gulp-concat' |
|
|
|
import { rollup } from 'rollup' |
|
|
|
import clean from 'gulp-clean' |
|
|
|
import commonjs from '@rollup/plugin-commonjs' |
|
|
|
import resolve from '@rollup/plugin-node-resolve' |
|
|
|
import terser from '@rollup/plugin-terser' |
|
|
|
import scss from 'rollup-plugin-scss' |
|
|
|
import javascriptObfuscator from 'gulp-javascript-obfuscator' |
|
|
|
import { babel } from '@rollup/plugin-babel' |
|
|
|
import startServer from './server.js' |
|
|
|
import inlineImage from 'esbuild-plugin-inline-image' |
|
|
|
import { sassPlugin } from 'esbuild-sass-plugin' |
|
|
|
import { glsl } from 'esbuild-plugin-glsl' |
|
|
|
import chokidar from 'chokidar' |
|
|
|
import shell from 'shelljs' |
|
|
|
import chalk from 'chalk' |
|
|
|
|
|
|
|
const packageJson = fse.readJsonSync('./package.json') |
|
|
|
|
|
|
|
const obfuscatorConfig = { |
|
|
|
compact: true, //压缩代码 |
|
|
|
identifierNamesGenerator: 'hexadecimal', //标识符的混淆方式 hexadecimal(十六进制) mangled(短标识符) |
|
|
|
@@ -54,31 +50,10 @@ const buildConfig = { |
|
|
|
limit: -1, |
|
|
|
}), |
|
|
|
glsl(), |
|
|
|
sassPlugin(), |
|
|
|
], |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
@@ -89,44 +64,22 @@ function getTime() { |
|
|
|
} |
|
|
|
|
|
|
|
async function buildNamespace(options) { |
|
|
|
const bundle = await rollup({ |
|
|
|
input: 'libs/index.js', |
|
|
|
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)) { |
|
|
|
return |
|
|
|
} |
|
|
|
if (message.code === 'CIRCULAR_DEPENDENCY') { |
|
|
|
return |
|
|
|
} |
|
|
|
console.log(message) |
|
|
|
}, |
|
|
|
}) |
|
|
|
return bundle.write({ |
|
|
|
name: 'DC.__namespace', |
|
|
|
file: options.node ? 'dist/namespace.cjs' : 'dist/namespace.js', |
|
|
|
format: options.node ? 'cjs' : 'umd', |
|
|
|
sourcemap: false, |
|
|
|
banner: options.node ? '(function(){' : '', |
|
|
|
footer: options.node ? '})()' : '', |
|
|
|
await esbuild.build({ |
|
|
|
...buildConfig, |
|
|
|
entryPoints: ['libs/index.js'], |
|
|
|
format: 'iife', |
|
|
|
globalName: options.node ? 'ns' : 'DC.__namespace', |
|
|
|
minify: options.minify, |
|
|
|
outfile: path.join('dist', options.node ? 'namespace.cjs' : 'namespace.js'), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
async function buildCSS() { |
|
|
|
const bundle = await rollup({ |
|
|
|
input: 'src/themes/index.js', |
|
|
|
plugins: [ |
|
|
|
commonjs(), |
|
|
|
resolve({ preferBuiltins: true }), |
|
|
|
scss({ |
|
|
|
outputStyle: 'compressed', |
|
|
|
fileName: 'dc.min.css', |
|
|
|
}), |
|
|
|
], |
|
|
|
}) |
|
|
|
return bundle.write({ |
|
|
|
file: 'dist/dc.min.css', |
|
|
|
async function buildCSS(options) { |
|
|
|
await esbuild.build({ |
|
|
|
...buildConfig, |
|
|
|
minify: options.minify, |
|
|
|
entryPoints: ['src/themes/index.scss'], |
|
|
|
outfile: path.join('dist', 'dc.min.css'), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -160,8 +113,8 @@ async function buildModules(options) { |
|
|
|
|
|
|
|
const exportNamespace = ` |
|
|
|
export const __namespace = { |
|
|
|
Cesium: exports.Cesium, |
|
|
|
Supercluster: exports.Supercluster |
|
|
|
Cesium: ns.Cesium, |
|
|
|
Supercluster: ns.Supercluster |
|
|
|
} |
|
|
|
` |
|
|
|
|
|
|
|
@@ -328,18 +281,18 @@ async function regenerate(option, content) { |
|
|
|
await fse.outputFile(path.join('dist', 'namespace.js'), content) |
|
|
|
await buildModules(option) |
|
|
|
await combineJs(option) |
|
|
|
await buildCSS() |
|
|
|
await buildCSS(option) |
|
|
|
} |
|
|
|
|
|
|
|
export const server = gulp.series(startServer) |
|
|
|
|
|
|
|
export const dev = gulp.series( |
|
|
|
() => buildNamespace({ dev: true }), |
|
|
|
() => buildNamespace({ iife: true }), |
|
|
|
copyAssets, |
|
|
|
() => { |
|
|
|
shell.echo(chalk.yellow('============= start dev ==============')) |
|
|
|
let jsContent = null |
|
|
|
const watcher = chokidar.watch('src', { |
|
|
|
const watcher = gulp.watch('src', { |
|
|
|
persistent: true, |
|
|
|
awaitWriteFinish: { |
|
|
|
stabilityThreshold: 1000, |
|
|
|
@@ -362,7 +315,7 @@ export const dev = gulp.series( |
|
|
|
} |
|
|
|
await regenerate({ iife: true }, jsContent) |
|
|
|
shell.echo( |
|
|
|
chalk.bgGreen(`regenerate lib takes ${new Date().getTime() - now} ms`) |
|
|
|
chalk.green(`regenerate lib takes ${new Date().getTime() - now} ms`) |
|
|
|
) |
|
|
|
}) |
|
|
|
return watcher |
|
|
|
@@ -370,39 +323,39 @@ export const dev = gulp.series( |
|
|
|
) |
|
|
|
|
|
|
|
export const buildNode = gulp.series( |
|
|
|
() => buildNamespace({ node: true }), |
|
|
|
() => buildNamespace({ node: true, minify: true }), |
|
|
|
() => buildModules({ node: true }), |
|
|
|
() => combineJs({ node: true }), |
|
|
|
buildCSS, |
|
|
|
() => buildCSS({ minify: true }), |
|
|
|
copyAssets |
|
|
|
) |
|
|
|
|
|
|
|
export const buildIIFE = gulp.series( |
|
|
|
() => buildNamespace({ iife: true }), |
|
|
|
() => buildNamespace({ iife: true, minify: true }), |
|
|
|
() => buildModules({ iife: true }), |
|
|
|
() => combineJs({ iife: true }), |
|
|
|
buildCSS, |
|
|
|
() => buildCSS({ minify: true }), |
|
|
|
copyAssets |
|
|
|
) |
|
|
|
|
|
|
|
export const build = gulp.series( |
|
|
|
() => buildNamespace({ node: true }), |
|
|
|
() => buildNamespace({ node: true, minify: true }), |
|
|
|
() => buildModules({ node: true }), |
|
|
|
() => combineJs({ node: true }), |
|
|
|
() => buildNamespace({ iife: true }), |
|
|
|
() => buildNamespace({ iife: true, minify: true }), |
|
|
|
() => buildModules({ iife: true }), |
|
|
|
() => combineJs({ iife: true }), |
|
|
|
buildCSS, |
|
|
|
() => buildCSS({ minify: true }), |
|
|
|
copyAssets |
|
|
|
) |
|
|
|
|
|
|
|
export const buildRelease = gulp.series( |
|
|
|
() => buildNamespace({ node: true }), |
|
|
|
() => buildNamespace({ node: true, minify: true }), |
|
|
|
() => buildModules({ node: true }), |
|
|
|
() => combineJs({ node: true, obfuscate: true }), |
|
|
|
() => buildNamespace({ iife: true }), |
|
|
|
() => buildNamespace({ iife: true, minify: true }), |
|
|
|
() => buildModules({ iife: true }), |
|
|
|
() => combineJs({ iife: true, obfuscate: true }), |
|
|
|
buildCSS, |
|
|
|
() => buildCSS({ minify: true }), |
|
|
|
copyAssets |
|
|
|
) |