ant-design/webpack.config.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-04-06 18:07:54 +08:00
const webpack = require('atool-build/lib/webpack');
module.exports = function(webpackConfig) {
2016-04-10 09:37:20 +08:00
// remove common.js
webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => {
return !(plugin instanceof webpack.optimize.CommonsChunkPlugin);
});
if (process.env.ANTD === 'WEBSITE') {
2016-04-08 15:29:04 +08:00
const component = process.env.COMPONENT_STYLE;
webpackConfig.entry = {
index: './site/entry/index.jsx',
};
webpackConfig.resolve.root = process.cwd();
webpackConfig.resolve.alias = {
2016-04-08 15:29:04 +08:00
antd: process.cwd(),
BrowserDemo: 'site/component/BrowserDemo',
};
2016-04-08 15:29:04 +08:00
if (component !== undefined) {
const babelConfig = require('atool-build/lib/getBabelCommonConfig')();
babelConfig.plugins.push([
'antd',
{
// style: true,
libDir: 'components',
}
]);
webpackConfig.module.loaders.push({
test: new RegExp(`components/${component}/demo/.*\.md`),
loader: `babel?${JSON.stringify(babelConfig)}!antd-md`,
});
}
const exclude = [/node_modules/];
if (component) {
exclude.push(new RegExp(`components/${component}/demo/.*\.md`));
}
webpackConfig.module.loaders.push({
test: /\.md$/,
exclude: exclude,
loader: `babel!antd-md`,
});
}
if (process.env.ANTD === 'PRODUCTION') {
2016-04-06 18:07:54 +08:00
const entry = ['./style/index.less', './index.js'];
webpackConfig.entry = {
2016-04-06 18:07:54 +08:00
'antd.min': entry,
};
webpackConfig.externals = {
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
2015-12-03 15:23:54 +08:00
}
};
webpackConfig.output.library = 'antd';
webpackConfig.output.libraryTarget = 'umd';
2016-04-06 18:07:54 +08:00
const uncompressedWebpackConfig = Object.assign({}, webpackConfig);
uncompressedWebpackConfig.entry = {
antd: entry,
};
uncompressedWebpackConfig.plugins = webpackConfig.plugins.filter((plugin) => {
return !(plugin instanceof webpack.optimize.UglifyJsPlugin);
});
return [
webpackConfig,
uncompressedWebpackConfig,
];
}
2015-06-16 20:10:30 +08:00
return webpackConfig;
2015-05-21 20:36:13 +08:00
};