Skip to content

Commit

Permalink
Merge pull request #1322 from finos/rollup-exports
Browse files Browse the repository at this point in the history
Export inline `@finos/perspective` by default, and simplify some package `dist` with rollup
  • Loading branch information
texodus authored Feb 11, 2021
2 parents b895d24 + 713a894 commit 8ae2e06
Show file tree
Hide file tree
Showing 21 changed files with 960 additions and 184 deletions.
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@babel/plugin-transform-for-of": "^7.8.4",
"@babel/preset-env": "^7.8.4",
"@rollup/plugin-babel": "^5.2.3",
"@rollup/plugin-node-resolve": "^11.1.1",
"@types/ws": "^7.2.2",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"@typescript-eslint/parser": "^2.4.0",
Expand Down Expand Up @@ -70,11 +72,16 @@
"mkdirp": "^0.5.1",
"npm-pack-here": "^1.2.0",
"npm-run-all": "^4.1.3",
"postcss": "^5.2.18",
"postcss": "^8.2.6",
"postcss-loader": "^4.1.0",
"pre-commit": "^1.2.2",
"prettier": "^1.19.1",
"rimraf": "^2.6.2",
"rollup": "^2.38.5",
"rollup-plugin-filesize": "^9.1.0",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-string": "^3.0.0",
"sinon": "^7.3.1",
"string-replace-loader": "^3.0.1",
"style-loader": "^0.18.2",
Expand All @@ -94,7 +101,8 @@
"write-file-atomic": "2.4.1",
"webpack": "^5.14.0",
"react": "16.8.6",
"react-dom": "16.8.6"
"react-dom": "16.8.6",
"autoprefixer": "9.7.0"
},
"pre-commit": [
"precommit"
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer-d3fc/src/js/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

import {registerPlugin} from "@finos/perspective-viewer/dist/esm/utils.js";
import {registerPlugin} from "@finos/perspective-viewer/src/js/utils.js";
import charts from "../charts/charts";
import "./polyfills/index";
import "./template";
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer-d3fc/src/js/plugin/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import template from "../../html/d3fc-chart.html";
import {areArraysEqualSimple} from "../utils/utils";
import {initialiseStyles} from "../series/colorStyles";

import {bindTemplate} from "@finos/perspective-viewer/dist/esm/utils";
import {bindTemplate} from "@finos/perspective-viewer/src/js/utils";

const styleWithD3FC = `${style}${getD3FCStyles()}`;
const EXCLUDED_SETTINGS = ["crossValues", "mainValues", "splitValues", "filter", "data", "size", "colorStyles"];
Expand Down
13 changes: 6 additions & 7 deletions packages/perspective-viewer-datagrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "@finos/perspective-viewer-datagrid",
"version": "0.6.0",
"description": "Perspective.js",
"main": "dist/cjs/perspective-viewer-datagrid.js",
"module": "dist/cjs/perspective-viewer-datagrid.js",
"browser": "dist/cjs/perspective-viewer-datagrid.js",
"main": "dist/esm/perspective-viewer-datagrid.js",
"module": "dist/esm/perspective-viewer-datagrid.js",
"browser": "dist/esm/perspective-viewer-datagrid.js",
"unpkg": "dist/umd/perspective-viewer-datagrid.js",
"jsdelivr": "dist/umd/perspective-viewer-datagrid.js",
"files": [
Expand All @@ -16,10 +16,9 @@
"bench:build": "echo \"No Benchmarks\"",
"bench:run": "echo \"No Benchmarks\"",
"prebuild": "mkdirp dist/esm",
"build:babel": "cpx \"src/**/*\" dist && babel src/js --source-maps --out-dir dist/esm",
"build:webpack:esm": "webpack --color --config src/config/cjs.config.js",
"build:webpack:umd": "webpack --color --config src/config/umd.config.js",
"build": "npm-run-all build:babel build:webpack:esm build:webpack:umd",
"build:rollup:esm": "rollup --config src/config/rollup.config.js",
"build:webpack:umd": "webpack --color --config src/config/webpack.config.js",
"build": "npm-run-all build:rollup:esm build:webpack:umd",
"test:build": "cpx \"test/html/*\" dist/umd",
"test:run": "jest --rootDir=. --config=../perspective-test/jest.config.js --color",
"test": "npm-run-all test:build test:run",
Expand Down
15 changes: 0 additions & 15 deletions packages/perspective-viewer-datagrid/src/config/cjs.config.js

This file was deleted.

41 changes: 41 additions & 0 deletions packages/perspective-viewer-datagrid/src/config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import babel from "@rollup/plugin-babel";
import filesize from "rollup-plugin-filesize";
import postcss from "rollup-plugin-postcss";
import sourcemaps from "rollup-plugin-sourcemaps";
import {nodeResolve} from "@rollup/plugin-node-resolve";
import path from "path";

const PROJECT_PATH = path.resolve(__dirname, "..", "..");

export default () => {
return [
{
input: "src/js/plugin.js",
external: id => {
let include = id.startsWith(".") || require.resolve(id).indexOf(PROJECT_PATH) === 0 || id.endsWith(".less");
return !include;
},
output: {
sourcemap: true,
file: "dist/esm/perspective-viewer-datagrid.js"
},
plugins: [
nodeResolve(),
babel({
exclude: "node_modules/**",
babelHelpers: "bundled"
}),
filesize(),
postcss({
inject: false,
sourceMap: true,
minimize: {preset: "lite"}
}),
sourcemaps()
].filter(x => x),
watch: {
clearScreen: false
}
}
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require("@finos/perspective/src/config/common.config.js");

module.exports = common({}, config =>
Object.assign(config, {
entry: "./dist/esm/plugin.js",
entry: "./dist/esm/perspective-viewer-datagrid.js",
output: {
filename: "perspective-viewer-datagrid.js",
library: "perspective-viewer-datagrid",
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer-datagrid/src/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

import {registerPlugin} from "@finos/perspective-viewer/dist/esm/utils.js";
import {registerPlugin} from "@finos/perspective-viewer/src/js/utils.js";

import "regular-table";
import {createModel, configureRegularTable, formatters} from "./regular_table_handlers.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "~regular-table/src/less/material.less";
@import (less) "~regular-table/dist/examples/perspective.css";
@import (less) "regular-table/src/less/material.less";
@import (less) "regular-table/dist/examples/perspective.css";

// Row Selection

Expand Down
21 changes: 10 additions & 11 deletions packages/perspective-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
"name": "@finos/perspective-viewer",
"version": "0.6.0",
"description": "Perspective.js",
"main": "dist/cjs/perspective-viewer.js",
"module": "dist/cjs/perspective-viewer.js",
"main": "dist/esm/viewer.js",
"module": "dist/esm/viewer.js",
"unpkg": "dist/umd/perspective-viewer.js",
"jsdelivr": "dist/umd/perspective-viewer.js",
"browser": {
"themes/all-themes.less": "./dist/themes/all-themes.less",
"themes/all-themes.less": "./src/themes/all-themes.less",
"themes/all-themes.css": "./dist/umd/all-themes.css",
"themes/material.less": "./dist/themes/material.less",
"themes/material.less": "./src/themes/material.less",
"themes/material.css": "./dist/umd/material.css",
"themes/material.dark.less": "./dist/themes/material.dark.less",
"themes/material.dark.less": "./src/themes/material.dark.less",
"themes/material.dark.css": "./dist/umd/material.dark.css",
"themes/material-dense.less": "./dist/themes/material-dense.less",
"themes/material-dense.less": "./src/themes/material-dense.less",
"themes/material-dense.css": "./dist/umd/material-dense.css",
"themes/material-dense.dark.less": "./dist/themes/material-dense.dark.less",
"themes/material-dense.dark.less": "./src/themes/material-dense.dark.less",
"themes/material-dense.dark.css": "./dist/umd/material-dense.dark.css"
},
"files": [
"dist/**/*",
"src/**/*",
"index.d.ts"
],
"typings": "index.d.ts",
"scripts": {
"bench": "npm-run-all bench:build bench:run",
"bench:build": "echo \"No Benchmarks\"",
"bench:run": "echo \"No Benchmarks\"",
"prebuild": "mkdirp dist/esm",
"build:babel": "cpx \"src/**/*\" dist && babel src/js --source-maps --out-dir dist/esm",
"build:webpack:umd": "webpack --color --config src/config/umd.config.js",
"build:webpack:cjs": "webpack --color --config src/config/cjs.config.js",
"build": "npm-run-all --silent build:babel build:webpack:cjs build:webpack:umd",
"build:rollup:esm": "rollup --config src/config/rollup.config.js",
"build": "npm-run-all --silent build:rollup:esm build:webpack:umd",
"watch": "webpack --color --watch --config src/config/view.config.js",
"test:build": "cpx \"test/html/*\" dist/umd && cpx \"test/csv/*\" dist/umd && cpx \"test/css/*\" dist/umd",
"test:run": "jest --rootDir=. --config=../perspective-test/jest.config.js --color 2>&1",
Expand Down
14 changes: 0 additions & 14 deletions packages/perspective-viewer/src/config/cjs.config.js

This file was deleted.

66 changes: 66 additions & 0 deletions packages/perspective-viewer/src/config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import babel from "@rollup/plugin-babel";
import {string} from "rollup-plugin-string";
import filesize from "rollup-plugin-filesize";
import postcss from "rollup-plugin-postcss";
import sourcemaps from "rollup-plugin-sourcemaps";
import {nodeResolve} from "@rollup/plugin-node-resolve";
import path from "path";
import fs from "fs";

const THEMES = fs.readdirSync(path.resolve(__dirname, "..", "themes"));
const PROJECT_PATH = path.resolve(__dirname, "..", "..");

export default () => {
function reducer(key, val) {
return {
input: `${val}`,
output: {
dir: "dist/umd"
},
plugins: [
postcss({
inject: false,
extract: path.resolve(`dist/umd/${key}.css`),
sourceMap: true,
minimize: {preset: "lite"}
}),
sourcemaps()
]
};
}

return [
...THEMES.map(theme => reducer(theme.replace(".less", ""), path.resolve(__dirname, "..", "themes", theme))),
{
input: "src/js/viewer.js",
external: id => {
let include = id.startsWith(".") || require.resolve(id).indexOf(PROJECT_PATH) === 0 || id.endsWith(".css");
return !include;
},
output: {
sourcemap: true,
dir: "dist/esm/"
},
plugins: [
nodeResolve(),
babel({
exclude: "node_modules/**",
babelHelpers: "bundled"
}),
string({
include: "**/*.html"
}),
filesize(),
postcss({
inject: false,
sourceMap: true,
minimize: {preset: "lite"}
}),
sourcemaps()
].filter(x => x),
watch: {
clearScreen: false
}
}
];
};
64 changes: 1 addition & 63 deletions packages/perspective-viewer/src/config/umd.config.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,9 @@
const path = require("path");
const fs = require("fs");
const cssnano = require("cssnano");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const common = require("@finos/perspective/src/config/common.config.js");
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const THEMES = fs.readdirSync(path.resolve(__dirname, "..", "themes"));

function try_delete(name) {
const filePath = path.resolve(__dirname, "..", "..", "dist", "umd", name);
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
}

function reducer(obj, key, val) {
obj[key] = val;
return obj;
}

module.exports = common({}, config => {
config.plugins.push(
new MiniCssExtractPlugin({
filename: "[name].css"
})
);

config.plugins.push({
apply: compiler => {
compiler.hooks.afterEmit.tap("AfterEmitPlugin", () => {
for (const theme of THEMES) {
try_delete(theme.replace("less", "js"));
try_delete(theme.replace("less", "js.map"));
}
});
}
});

config.plugins.push(new FixStyleOnlyEntriesPlugin());
config.module.rules.push({
test: /\.(woff|ttf|eot|svg|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "base64-font-loader"
});

config.module.rules.push({
test: /themes[\\/].+?\.less$/,
use: [
{loader: MiniCssExtractPlugin.loader},
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
minimize: true,
plugins: [
cssnano({
preset: "lite"
})
]
}
}
},
"less-loader"
]
});

return Object.assign(config, {
entry: THEMES.reduce((obj, theme) => reducer(obj, theme.replace(".less", ""), path.resolve(__dirname, "..", "themes", theme)), {"perspective-viewer": "./dist/cjs/perspective-viewer.js"}),
entry: {"perspective-viewer": "./dist/esm/viewer.js"},
output: {
filename: "[name].js",
libraryTarget: "umd",
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer/src/js/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import debounce from "lodash/debounce";

import Awesomplete from "awesomplete";
import awesomplete_style from "!!css-loader!awesomplete/awesomplete.css";
import awesomplete_style from "awesomplete/awesomplete.css";

import {bindTemplate} from "./utils.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-workspace/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import style from "../less/workspace.less";
import template from "../html/workspace.html";
import {bindTemplate} from "@finos/perspective-viewer/dist/esm/utils";
import {bindTemplate} from "@finos/perspective-viewer/src/js/utils";
import {PerspectiveWorkspace, SIDE} from "./workspace";
import {MessageLoop} from "@lumino/messaging";
import {Widget} from "@lumino/widgets";
Expand Down
4 changes: 2 additions & 2 deletions packages/perspective/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "dist/cjs/perspective.node.js",
"unpkg": "dist/umd/perspective.js",
"jsdelivr": "dist/umd/perspective.js",
"browser": "dist/esm/perspective.parallel.js",
"module": "dist/esm/perspective.parallel.js",
"browser": "dist/umd/perspective.inline.js",
"module": "dist/umd/perspective.inline.js",
"publishConfig": {
"access": "public"
},
Expand Down
Loading

0 comments on commit 8ae2e06

Please sign in to comment.