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

build: group webpack & ignore dist & support yarn1.x #2546

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist/**
.github/**
yarn.lock
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ node_modules/
coverage/
.idea/

dist/*.js
dist/*.map
dist

yarn-error.log
.npmrc
token

package-lock.json

dist/classTest.html

dist/sequenceTest.html

.vscode/
cypress/platform/current.html
cypress/platform/experimental.html
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*": [
"yarn lint:fix"
"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',
},
},
],
},
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading