g6/webpack.config.js

78 lines
1.9 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: [
{
2019-11-18 02:47:44 +08:00
// 用于web worker代码。注意这条规则必须在.js规则前面
// 这样.worker.js会经过['worker-loader', 'babel-loader']处理
test: /\.worker\.js$/,
exclude: /(node_modules|bower_components)/,
2018-06-05 23:58:10 +08:00
use: {
2019-11-18 02:47:44 +08:00
loader: 'worker-loader',
2018-06-05 23:58:10 +08:00
options: {
2019-11-18 02:47:44 +08:00
inline: true,
2019-11-18 12:50:57 +08:00
fallback: false,
name: 'g6Layout.worker.js'
2018-06-05 23:58:10 +08:00
}
}
2018-07-22 18:02:53 +08:00
},
{
2019-11-18 02:47:44 +08:00
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
babelrc: true
}
2018-07-22 18:32:26 +08:00
}
2018-06-05 23:58:10 +08:00
}
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.AggressiveMergingPlugin()
]
};