Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from browserify to webpack in order to be able to use most recent ES modules & allow JavaScript syntax beyond ES5 #6355

Merged
merged 27 commits into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dc23266
switch from browserify to webpack & convert es6 to es5
archmoj Oct 25, 2022
834d411
skip no new-func for now
archmoj Oct 31, 2022
6b5b4c4
fix minified custom bundle script
archmoj Nov 1, 2022
2ddf5d6
improve handling of webpack when stats.error is empty but hasErrors
archmoj Nov 3, 2022
9818452
use webpack to generate strict regl code
archmoj Nov 3, 2022
047fda8
install raw-loader - uninstall browserify
archmoj Nov 7, 2022
bbf19c1
use ify-loader and raw-loader to compile glslify
archmoj Nov 7, 2022
4cdc04b
configuration for bundling stackgl using webpack
archmoj Nov 8, 2022
524f24d
bundle stackgl using webpack
archmoj Nov 8, 2022
3c42b19
ignore LICENSE.txt output files in dist
archmoj Nov 8, 2022
3a50892
replace webpack hasErrors calls - bug creates long logs
archmoj Nov 8, 2022
0abfdac
fix & update bundle options
archmoj Nov 8, 2022
addc012
delete tasks/util/strict_d3.js
archmoj Nov 9, 2022
d8161fb
remove watch script & delete tasks/watch.js
archmoj Nov 9, 2022
18d0bf3
create server & open browser after the first bundle
archmoj Nov 9, 2022
06226c3
pngjs is used by pixelmatch which is dev-dep
archmoj Nov 9, 2022
9fc5987
no need for buffer & asser fallbacks
archmoj Nov 9, 2022
d5a618c
Revert "skip no new-func for now"
archmoj Nov 9, 2022
937d65c
fixup webpack error handling
archmoj Nov 11, 2022
d2d03c0
no-new-func warn on all plotly.js outpus
archmoj Nov 11, 2022
7a289c5
revise no-new-func tests
archmoj Nov 11, 2022
fab0628
no longer need to run unexpected chars tests on CI which is slow
archmoj Nov 11, 2022
3b3211f
update BUILDING.md
archmoj Nov 11, 2022
ebc6530
update CONTRIBUTING.md
archmoj Nov 11, 2022
2cca25f
update README.md
archmoj Nov 11, 2022
ebd130e
draft log for PR 6355
archmoj Nov 11, 2022
458921f
use development mode and devtool option to improve debugging experience
archmoj Dec 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions .circleci/config.yml
Expand Up @@ -404,13 +404,7 @@ jobs:
name: Test plotly.min.js import using requirejs
command: npm run test-requirejs
- run:
name: Test plotly bundles againt unexpected characters
command: npm run no-bad-char
- run:
name: Display function constructors in plotly.js bundle
command: npm run log-new-func
- run:
name: Test certain bundles against function constructors
name: Display function constructors in all bundles
command: npm run no-new-func
- run:
name: Test plotly bundles against es6
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,6 +4,8 @@ build/*
!build/plotcss.js
!build/README.md

dist/*.LICENSE.txt

npm-debug.log*
*.sublime*
*~
Expand Down
35 changes: 0 additions & 35 deletions BUILDING.md
Expand Up @@ -3,41 +3,6 @@ Depending on your needs you may require/import one of [the distributed plotly.js

The sections below provide additional info in respect to alternative building frameworks.

## Browserify example

Given source file:
```js
// file: index.js
var Plotly = require('plotly.js-dist-min');
// ....
```

then simply run

```sh
browserify index.js > bundle.js
```

---
## Webpack

For plotly.js to build with Webpack you will need to install [ify-loader@v1.1.0+](https://github.com/hughsk/ify-loader) and add it to your `webpack.config.json`. This adds Browserify transform compatibility to Webpack which is necessary for some plotly.js dependencies.

A repo that demonstrates how to build plotly.js with Webpack can be found [here](https://github.com/plotly/plotly-webpack). In short add `ify-loader` to the `module` section in your `webpack.config.js`:

```js
...
module: {
rules: [
{
test: /\.js$/,
loader: 'ify-loader'
}
]
},
...
```

---
## Angular CLI

Expand Down
6 changes: 1 addition & 5 deletions CONTRIBUTING.md
Expand Up @@ -116,11 +116,7 @@ npm run pretest
npm start
```

This command bundles up the source files with source maps using
[browserify](https://github.com/substack/node-browserify), starts a
[watchify](https://github.com/substack/watchify) file watcher (making your
dev plotly.js bundle update every time a source file is saved) and opens up a
tab in your browser.
This command bundles up the source files and opens up a tab in your browser.

#### Step 6: Open up the console and start developing

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -108,7 +108,7 @@ There are two kinds of plotly.js bundles:

---
## Alternative ways to load and build plotly.js
If your library needs to bundle or directly load [plotly.js/lib/index.js](https://github.com/plotly/plotly.js/blob/master/lib/index.js) or parts of its modules similar to [index-basic](https://github.com/plotly/plotly.js/blob/master/lib/index-basic.js) in some other way than via an official or a custom bundle, or in case you want to tweak the default build configurations of `browserify` or `webpack`, etc. then please visit [`BUILDING.md`](https://github.com/plotly/plotly.js/blob/master/BUILDING.md).
If your library needs to bundle or directly load [plotly.js/lib/index.js](https://github.com/plotly/plotly.js/blob/master/lib/index.js) or parts of its modules similar to [index-basic](https://github.com/plotly/plotly.js/blob/master/lib/index-basic.js) in some other way than via an official or a custom bundle, or in case you want to tweak the default build configurations, then please visit [`BUILDING.md`](https://github.com/plotly/plotly.js/blob/master/BUILDING.md).

---
## Documentation
Expand Down
4 changes: 3 additions & 1 deletion devtools/regl_codegen/devtools.js
Expand Up @@ -4,7 +4,7 @@

var mocks = require('../../build/test_dashboard_mocks.json');
var reglTraces = require('../../build/regl_traces.json');
var Lib = require('@src/lib');
var Lib = require('../../src/lib');

// Our gracious testing object
var Tabs = {
Expand Down Expand Up @@ -158,3 +158,5 @@ function handleOnLoad() {
window.close();
});
}

module.exports = Tabs;
87 changes: 48 additions & 39 deletions devtools/regl_codegen/server.js
Expand Up @@ -3,17 +3,24 @@ var path = require('path');
var http = require('http');
var ecstatic = require('ecstatic');
var open = require('open');
var browserify = require('browserify');
var webpack = require('webpack');
var minimist = require('minimist');

var constants = require('../../tasks/util/constants');
var makeWatchifiedBundle = require('../../tasks/util/watchified_bundle');
var shortcutPaths = require('../../tasks/util/shortcut_paths');
var config = require('../../webpack.config.js');
config.optimization = { minimize: false };

var args = minimist(process.argv.slice(2), {});
var PORT = args.port || 3000;
var strict = args.strict;

var reglTraceList = [
'parcoords',
'scattergl',
'scatterpolargl',
'splom'
];

// Create server
var static = ecstatic({
root: constants.pathToRoot,
Expand Down Expand Up @@ -51,38 +58,53 @@ var server = http.createServer(function(req, res) {
});


// Make watchified bundle for plotly.js
var bundlePlotly = makeWatchifiedBundle(strict, function() {
// open up browser window on first bundle callback
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');
});

// Bundle devtools code
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
var devtools = browserify(path.join(devtoolsPath, 'devtools.js'), {
transform: [shortcutPaths]
});

// Start the server up!
server.listen(PORT);

var reglTraceList = [
'parcoords',
'scattergl',
'scatterpolargl',
'splom'
];

purgeGeneratedCode(reglTraceList);
// open up browser window
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');

// Build and bundle all the things!
getMockFiles()
.then(readFiles)
.then(createMocksList)
.then(saveMockListToFile)
.then(saveReglTracesToFile.bind(null, reglTraceList))
.then(bundleDevtools)
.then(bundlePlotly);
.then(saveReglTracesToFile.bind(null, reglTraceList));

// Devtools config
var devtoolsConfig = {};

var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js');

devtoolsConfig.output = {
path: config.output.path,
filename: 'regl_codegen-bundle.js',
library: {
name: 'Tabs',
type: 'umd'
}
};

devtoolsConfig.target = config.target;
devtoolsConfig.plugins = config.plugins;
devtoolsConfig.optimization = config.optimization;
devtoolsConfig.mode = 'production';

var compiler;

compiler = webpack(devtoolsConfig);
compiler.run(function(devtoolsErr, devtoolsStats) {
if(devtoolsErr) {
console.log('err:', devtoolsErr);
} else if(devtoolsStats.errors && devtoolsStats.errors.length) {
console.log('stats.errors:', devtoolsStats.errors);
} else {
console.log('success:', devtoolsConfig.output.path + '/' + devtoolsConfig.output.filename);

purgeGeneratedCode(reglTraceList);
}
});


function getMockFiles() {
Expand Down Expand Up @@ -178,19 +200,6 @@ function writeFilePromise(path, contents) {
});
}

function bundleDevtools() {
return new Promise(function(resolve, reject) {
devtools.bundle(function(err) {
if(err) {
console.error('Error while bundling!', JSON.stringify(String(err)));
return reject(err);
} else {
return resolve();
}
}).pipe(fs.createWriteStream(constants.pathToReglCodegenBundle));
});
}

function handleCodegen(data) {
var trace = data.trace;
var generated = data.generated;
Expand Down
4 changes: 3 additions & 1 deletion devtools/test_dashboard/devtools.js
Expand Up @@ -5,7 +5,7 @@
var Fuse = require('fuse.js/dist/fuse.common.js');
var mocks = require('../../build/test_dashboard_mocks.json');
var credentials = require('../../build/credentials.json');
var Lib = require('@src/lib');
var Lib = require('../../src/lib');

require('./perf');

Expand Down Expand Up @@ -268,3 +268,5 @@ function handleOnLoad() {
Tabs.setPlotConfig();
plotFromHash();
}

module.exports = Tabs;