g6/webpack.config.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-06-05 23:58:10 +08:00
const webpack = require('webpack');
const resolve = require('path').resolve;
2019-03-20 15:06:36 +08:00
const shelljs = require('shelljs');
2018-06-05 23:58:10 +08:00
const _ = require('lodash');
const entry = {
2019-03-20 15:06:36 +08:00
G6: './src/index.js',
G6Plugins: './plugins/index.js'
2018-06-05 23:58:10 +08:00
};
2019-03-20 15:06:36 +08:00
shelljs.ls(resolve(__dirname, 'plugins')).forEach(pluginPath => {
if (pluginPath === 'base.js') return;
if (pluginPath !== 'index.js') {
const fileDirs = pluginPath.split('-');
let moduleName = '';
for (let i = 0; i < fileDirs.length; i++) {
const segment = fileDirs[i];
moduleName += (segment.charAt(0).toUpperCase() + segment.substring(1));
}
entry[moduleName] = `./plugins/${pluginPath}/index.js`;
} else {
const moduleName = 'plugins';
entry[moduleName] = './plugins/index.js';
}
});
2018-06-05 23:58:10 +08:00
module.exports = {
mode: 'production',
devtool: 'cheap-source-map',
entry,
output: {
filename: substitutions => `${_.lowerFirst(substitutions.chunk.name)}.js`,
library: '[name]',
libraryTarget: 'umd',
path: resolve(__dirname, 'build/')
},
externals: {
2018-07-12 21:38:24 +08:00
'@antv/g6': {
root: 'G6',
commonjs2: '@antv/g6',
commonjs: '@antv/g6',
amd: '@antv/g6'
}
2018-06-05 23:58:10 +08:00
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
2018-06-05 23:58:10 +08:00
use: {
loader: 'babel-loader',
options: {
babelrc: true
}
}
2018-07-22 18:02:53 +08:00
},
{
test: /\.worker.js$/,
2018-07-22 18:32:26 +08:00
loader: 'worker-loader',
options: {
inline: true
}
2018-06-05 23:58:10 +08:00
}
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
]
};