Skip to content

Commit

Permalink
fix(merge): fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Nov 14, 2019
2 parents 10cbfb3 + 4185022 commit 07e8505
Show file tree
Hide file tree
Showing 27 changed files with 995 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jspm_packages/
# End of https://www.gitignore.io/api/node

lib/
dist/

.DS_Store
public
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Alipay.inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 12 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = (api) => {
browsers: 'Last 2 Chrome versions, Firefox ESR',
node: 'current',
},
// set `modules: false` when building CDN bundle, let rollup do commonjs works
// @see https://github.com/rollup/rollup-plugin-babel#modules
modules: api.env('bundle') ? false : 'auto',
},
],
[
Expand Down Expand Up @@ -65,8 +68,11 @@ module.exports = (api) => {
}
],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-modules-commonjs',
[
// let rollup do commonjs works
// @see https://github.com/rollup/rollup-plugin-babel#modules
api.env('bundle') ? {} : '@babel/plugin-transform-modules-commonjs',
// 开发模式下以原始文本引入,便于调试
api.env('bundle') ? {} : [
// import glsl as raw text
'babel-plugin-inline-import',
{
Expand All @@ -84,11 +90,10 @@ module.exports = (api) => {
transform: 'constObject',
}
],
// TODO:减少最终打包产物大小
// 1. 去除 Shader 中的注释
// @see https://www.npmjs.com/package/babel-plugin-remove-glsl-comments
// 2. 内联 WebGL 常量
// @see https://www.npmjs.com/package/babel-plugin-inline-webgl-constants
// 按需引用 @see https://github.com/lodash/babel-plugin-lodash
'lodash',
// 内联 WebGL 常量 @see https://www.npmjs.com/package/babel-plugin-inline-webgl-constants
api.env('bundle') ? 'inline-webgl-constants' : {},
],
env: {
build: {
Expand Down
4 changes: 4 additions & 0 deletions build/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
export * from '@l7/scene';
// @ts-ignore
export * from '@l7/layers';
33 changes: 33 additions & 0 deletions build/rollup-plugin-glsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createFilter } from 'rollup-pluginutils';

// borrow from https://github.com/uber/luma.gl/blob/master/dev-modules/babel-plugin-remove-glsl-comments/index.js#L4-L5
const INLINE_COMMENT_REGEX = /\s*\/\/.*[\n\r]/g;
const BLOCK_COMMENT_REGEX = /\s*\/\*(\*(?!\/)|[^*])*\*\//g;

// 生产环境压缩 GLSL
export default function glsl(include, minify) {
const filter = createFilter(include);
return {
name: 'glsl',
transform(code, id) {
if (!filter(id)) return;

if (minify) {
code = code
.trim() // strip whitespace at the start/end
.replace(/\n+/g, '\n') // collapse multi line breaks
// remove comments
.replace(INLINE_COMMENT_REGEX, '\n')
.replace(BLOCK_COMMENT_REGEX, '')
.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: '' }
};
}
};
}
79 changes: 79 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import path from 'path';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from "rollup-plugin-terser";
import analyze from 'rollup-plugin-analyzer';
import babel from 'rollup-plugin-babel';
import glsl from './rollup-plugin-glsl';

function resolveFile(filePath) {
return path.join(__dirname, '..', filePath)
}

module.exports = [
{
input: resolveFile('build/bundle.ts'),
output: {
file: resolveFile('dist/bundle.js'),
format: 'umd',
name: 'L7',
globals: {
'mapbox-gl': 'mapboxgl',
},
},
external: [
'mapbox-gl',
],
treeshake: true,
plugins: [
alias(
{
resolve: ['.tsx', '.ts'],
entries: [
{
find: /^@l7\/(.*)/,
replacement: resolveFile('packages/$1/src'),
},
]
},
),
resolve({
browser: true,
preferBuiltins: false,
extensions: ['.js', '.ts'],
}),
glsl(
['**/*.glsl'],
true,
),
json(),
// @see https://github.com/rollup/rollup-plugin-node-resolve#using-with-rollup-plugin-commonjs
commonjs({
namedExports: {
eventemitter3: [ 'EventEmitter' ],
// @see https://github.com/rollup/rollup-plugin-commonjs/issues/266
lodash: [
'isNil',
'uniq',
'clamp',
'isObject',
'isFunction',
'cloneDeep',
'isString',
'isNumber',
],
}
}),
babel({
extensions: ['.js', '.ts'],
}),
terser(),
analyze({
summaryOnly: true,
limit: 20,
}),
],
},
];
Loading

0 comments on commit 07e8505

Please sign in to comment.