Skip to content

Commit

Permalink
build: group webpack & ignore dist & support yarn1.x (mermaid-js#2551)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorel-35 authored Dec 11, 2021
1 parent 67143b7 commit 4cd2621
Show file tree
Hide file tree
Showing 26 changed files with 835 additions and 144,456 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ node_modules/
coverage/
.idea/

dist/
dist

yarn-error.log
.npmrc
Expand Down
Empty file modified .husky/pre-commit
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"*.{js,html,md}": [
"yarn lint:fix"
]
}
}
15 changes: 14 additions & 1 deletion src/jison/loader.js → .webpack/loaders/jison.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
const { Generator } = require('jison');
const validate = require('schema-utils');
const schema = require('./parser-options-schema.json');

const schema = {
title: 'Jison Parser options',
type: 'object',
properties: {
'token-stack': {
type: 'boolean',
},
debug: {
type: 'boolean',
},
},
additionalProperties: false,
};

module.exports = function jisonLoader(source) {
const options = this.getOptions();
Expand Down
45 changes: 45 additions & 0 deletions .webpack/webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { merge, mergeWithCustomize, customizeObject } from 'webpack-merge';
import nodeExternals from 'webpack-node-externals';
import baseConfig from './webpack.config.base';

export default (_env, args) => {
switch (args.mode) {
case 'development':
return [
baseConfig,
merge(baseConfig, {
externals: [nodeExternals()],
output: {
filename: '[name].core.js',
},
}),
];
case 'production':
return [
// umd
merge(baseConfig, {
output: {
filename: '[name].min.js',
},
}),
// esm
mergeWithCustomize({
customizeObject: customizeObject({
'output.library': 'replace',
}),
})(baseConfig, {
experiments: {
outputModule: true,
},
output: {
library: {
type: 'module',
},
filename: '[name].esm.min.mjs',
},
}),
];
default:
throw new Error('No matching configuration was found!');
}
};
54 changes: 54 additions & 0 deletions .webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import path from 'path';

export const resolveRoot = (...relativePath) => path.resolve(__dirname, '..', ...relativePath);

export default {
amd: false, // https://github.com/lodash/lodash/issues/3052
target: 'web',
entry: {
mermaid: './src/mermaid.js',
},
resolve: {
extensions: ['.wasm', '.mjs', '.js', '.json', '.jison'],
fallback: {
fs: false, // jison generated code requires 'fs'
path: require.resolve('path-browserify'),
},
},
output: {
path: resolveRoot('./dist'),
filename: '[name].js',
library: {
name: 'mermaid',
type: 'umd',
export: 'default',
},
globalObject: 'typeof self !== "undefined" ? self : this',
},
module: {
rules: [
{
test: /\.js$/,
include: [resolveRoot('./src'), resolveRoot('./node_modules/dagre-d3-renderer/lib')],
use: {
loader: 'babel-loader',
},
},
{
// load scss to string
test: /\.scss$/,
use: ['css-to-string-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.jison$/,
use: {
loader: path.resolve(__dirname, './loaders/jison.js'),
options: {
'token-stack': true,
},
},
},
],
},
devtool: 'source-map',
};
37 changes: 37 additions & 0 deletions .webpack/webpack.config.e2e.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import baseConfig, { resolveRoot } from './webpack.config.base';
import { merge } from 'webpack-merge';

export default merge(baseConfig, {
mode: 'development',
entry: {
mermaid: './src/mermaid.js',
e2e: './cypress/platform/viewer.js',
'bundle-test': './cypress/platform/bundle-test.js',
},
output: {
globalObject: 'window',
},
devServer: {
compress: true,
port: 9000,
static: [
{ directory: resolveRoot('cypress', 'platform') },
{ directory: resolveRoot('dist') },
{ directory: resolveRoot('demos') },
],
},
externals: {
mermaid: 'mermaid',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
});
14 changes: 7 additions & 7 deletions dist/dataflowchart.html → demos/dataflowchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ <h2>Borders Example</h2>
theme: 'forest',
logLevel: 3,
securityLevel: 'loose',
flowchart: { curve: 'basis' }
flowchart: { curve: 'basis' },
});
</script>
<script>
function testClick(nodeId) {
console.log("clicked", nodeId)
var originalBgColor = document.querySelector('body').style.backgroundColor
document.querySelector('body').style.backgroundColor = 'yellow'
setTimeout(function() {
document.querySelector('body').style.backgroundColor = originalBgColor
}, 100)
console.log('clicked', nodeId);
var originalBgColor = document.querySelector('body').style.backgroundColor;
document.querySelector('body').style.backgroundColor = 'yellow';
setTimeout(function () {
document.querySelector('body').style.backgroundColor = originalBgColor;
}, 100);
}
</script>
</body>
Expand Down
14 changes: 7 additions & 7 deletions dist/flowchart.html → demos/flowchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -1088,17 +1088,17 @@ <h1 id="link-clicked">Anchor for "link-clicked" test</h1>
theme: 'forest',
logLevel: 3,
securityLevel: 'loose',
flowchart: { curve: 'basis' }
flowchart: { curve: 'basis' },
});
</script>
<script>
function testClick(nodeId) {
console.log("clicked", nodeId)
var originalBgColor = document.querySelector('body').style.backgroundColor
document.querySelector('body').style.backgroundColor = 'yellow'
setTimeout(function() {
document.querySelector('body').style.backgroundColor = originalBgColor
}, 100)
console.log('clicked', nodeId);
var originalBgColor = document.querySelector('body').style.backgroundColor;
document.querySelector('body').style.backgroundColor = 'yellow';
setTimeout(function () {
document.querySelector('body').style.backgroundColor = originalBgColor;
}, 100);
}
</script>
</body>
Expand Down
28 changes: 14 additions & 14 deletions dist/index.html → demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -790,31 +790,31 @@ <h1 id="link-clicked">Anchor for "link-clicked" test</h1>
</script>
<script>
function ganttTestClick(a, b, c) {
console.log("a:", a)
console.log("b:", b)
console.log("c:", c)
console.log('a:', a);
console.log('b:', b);
console.log('c:', c);
}
function testClick(nodeId) {
console.log("clicked", nodeId)
var originalBgColor = document.querySelector('body').style.backgroundColor
document.querySelector('body').style.backgroundColor = 'yellow'
setTimeout(function() {
document.querySelector('body').style.backgroundColor = originalBgColor
}, 100)
console.log('clicked', nodeId);
var originalBgColor = document.querySelector('body').style.backgroundColor;
document.querySelector('body').style.backgroundColor = 'yellow';
setTimeout(function () {
document.querySelector('body').style.backgroundColor = originalBgColor;
}, 100);
}
</script>
<script>
const testLineEndings = (test, input) => {
try {
mermaid.render(test, input, () => { });
mermaid.render(test, input, () => {});
} catch (err) {
console.error("Error in %s:\n\n%s", test, err);
console.error('Error in %s:\n\n%s', test, err);
}
};

testLineEndings("CR", "graph LR\rsubgraph CR\rA --> B\rend");
testLineEndings("LF", "graph LR\nsubgraph LF\nA --> B\nend");
testLineEndings("CRLF", "graph LR\r\nsubgraph CRLF\r\nA --> B\r\nend");
testLineEndings('CR', 'graph LR\rsubgraph CR\rA --> B\rend');
testLineEndings('LF', 'graph LR\nsubgraph LF\nA --> B\nend');
testLineEndings('CRLF', 'graph LR\r\nsubgraph CRLF\r\nA --> B\r\nend');
</script>
</body>

Expand Down
Loading

0 comments on commit 4cd2621

Please sign in to comment.