antv-l7/rollup.config.js

108 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-03-01 11:23:01 +08:00
import fs from 'fs';
2019-07-02 20:27:23 +08:00
import json from 'rollup-plugin-json';
2019-03-01 14:54:05 +08:00
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
2019-07-02 20:27:23 +08:00
import builtins from 'rollup-plugin-node-builtins';
2019-03-01 14:54:05 +08:00
import { createFilter } from 'rollup-pluginutils';
import postcss from 'rollup-plugin-postcss';
2019-08-07 17:08:53 +08:00
import url from 'postcss-url';
2019-03-01 14:54:05 +08:00
import { terser } from 'rollup-plugin-terser';
2019-03-01 11:23:01 +08:00
const { BUILD, MINIFY } = process.env;
const minified = MINIFY === 'true';
const production = BUILD === 'production';
const outputFile = !production
2019-03-01 14:54:05 +08:00
? 'build/L7.js'
2019-03-01 11:23:01 +08:00
: minified
2019-08-01 20:40:09 +08:00
? 'build/L7-min.js'
: 'build/L7-unminified.js';
2019-03-01 11:23:01 +08:00
const config = [
{
input: [ 'src/index.js', 'src/worker/worker.js' ],
output: {
dir: 'rollup/build/l7',
format: 'amd',
sourcemap: 'inline',
indent: false,
chunkFileNames: 'shared.js'
},
2019-06-26 14:30:29 +08:00
// experimentalCodeSplitting: true,
2019-07-02 20:27:23 +08:00
treeshake: production,
onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
warn(warning);
},
2019-03-01 14:54:05 +08:00
plugins: [
glsl(
2019-06-26 14:30:29 +08:00
[ './src/geom/shader/*.glsl', './src/core/engine/picking/*.glsl', './src/geom/shader/**/*.glsl' ],
2019-03-01 14:54:05 +08:00
production
),
minified ? terser() : false,
2019-07-02 20:27:23 +08:00
json(),
// css({ raw: './build/l7.css' }),
postcss({
2019-08-07 17:08:53 +08:00
plugins: [ url({ url: 'inline' }) ]
}),
2019-08-07 15:40:42 +08:00
// url({ url: 'inline' }),
2019-03-01 14:54:05 +08:00
buble({
transforms: { dangerousForOf: true },
objectAssign: 'Object.assign'
}),
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
ignoreGlobal: true
2019-07-02 20:27:23 +08:00
}),
builtins()
2019-03-01 14:54:05 +08:00
]
2019-03-01 11:23:01 +08:00
},
{
2019-03-01 14:54:05 +08:00
input: 'rollup/l7.js',
2019-03-01 11:23:01 +08:00
output: {
2019-03-01 14:54:05 +08:00
name: 'L7',
2019-03-01 11:23:01 +08:00
file: outputFile,
format: 'umd',
sourcemap: production ? true : 'inline',
indent: false,
intro: fs.readFileSync(
require.resolve('./rollup/bundle_prelude.js'),
'utf8'
)
},
treeshake: false,
plugins: [
// css()
2019-03-01 11:23:01 +08:00
]
}
];
export default config;
2019-03-01 14:54:05 +08:00
function glsl(include, minify) {
const filter = createFilter(include);
return {
name: 'glsl',
transform(code, id) {
if (!filter(id)) return;
// barebones GLSL minification
if (minify) {
code = code
.trim() // strip whitespace at the start/end
.replace(/\s*\/\/[^\n]*\n/g, '\n') // strip double-slash comments
.replace(/\n+/g, '\n') // collapse multi line breaks
.replace(/\n\s+/g, '\n') // strip identation
.replace(/\s?([+-\/*=,])\s?/g, '$1') // strip whitespace around operators
.replace(/([;\(\),\{\}])\n(?=[^#])/g, '$1'); // strip more line breaks
}
return {
code: `export default ${JSON.stringify(code)};`,
map: { mappings: '' }
};
}
};
}