Skip to content

Commit

Permalink
build: use rollup for better tree-shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Oct 12, 2020
1 parent 59a2883 commit 4c32a0c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"presets": [
["@babel/preset-env",
{
"modules": false,
"targets": {
"browsers": [
"> 1%",
Expand All @@ -27,4 +28,4 @@
}
]
]
}
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "spritejs",
"version": "3.7.27",
"description": "A cross platform high-performance graphics system.",
"module": "dist/spritejs.esm.js",
"main": "dist/spritejs.js",
"typings": "typings/spritejs.d.ts",
"module": "lib/index.js",
"scripts": {
"test": "jest --coverage",
"test:build": "jest --updateSnapshot --coverage",
Expand Down Expand Up @@ -42,6 +42,10 @@
"@babel/register": "^7.8.6",
"@demosify/core": "^0.6.0",
"@purtuga/esm-webpack-plugin": "^1.2.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.6",
"babel-plugin-transform-gl-matrix": "^0.6.0",
Expand All @@ -56,6 +60,9 @@
"node-canvas-webgl": "^0.2.6",
"raw-loader": "^3.1.0",
"request": "^2.88.0",
"rollup": "^2.29.0",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-string": "^3.0.0",
"webpack": "^4.33.0",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "^3.11.0"
Expand Down
49 changes: 49 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import {string} from 'rollup-plugin-string';
import globals from 'rollup-plugin-node-globals';

const pkg = require('./package.json');

/** @type {import('rollup').RollupOptions} */
const config = {
input: './src/index',
output: [
{
format: 'es',
sourcemap: true,
file: pkg.module,
},
{
format: 'umd',
name: 'spritejs',
sourcemap: true,
file: pkg.main,
},
],
plugins: [
babel({
babelHelpers: 'runtime',
skipPreflightCheck: true,
exclude: /node_modules/,
}),
json(),
resolve(),
commonjs({
transformMixedEsModules: true,
}),
string({
include: ['**/*.frag', '**/*.vert', '**/*.glsl'],
}),
globals({
process: false,
buffer: false,
dirname: false,
filename: false,
}),
],
};

export default config;

0 comments on commit 4c32a0c

Please sign in to comment.