ant-design/webpack.config.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-04-06 18:07:54 +08:00
const webpack = require('atool-build/lib/webpack');
2016-04-14 11:27:31 +08:00
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
2016-04-14 10:33:01 +08:00
const babelConfig = require('atool-build/lib/getBabelCommonConfig')();
babelConfig.plugins.push([
'antd',
{
// style: true,
libDir: 'components',
}
]);
const componentRegExp = component && new RegExp(`components/${component.toLowerCase()}/demo/.*\.md`);
webpackConfig.module.loaders.push({
test: component ? componentRegExp : /\.md$/,
exclude: /node_modules/,
loader: `babel?${JSON.stringify(babelConfig)}!antd-md`,
});
2016-04-08 15:29:04 +08:00
2016-04-14 10:33:01 +08:00
if (component !== undefined) {
2016-04-08 15:29:04 +08:00
webpackConfig.module.loaders.push({
2016-04-14 10:33:01 +08:00
test: /\.md$/,
exclude: [/node_modules/, componentRegExp],
2016-04-14 11:27:31 +08:00
loader: 'babel!antd-md',
2016-04-08 15:29:04 +08:00
});
}
}
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 = {
2016-04-14 11:27:31 +08:00
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
};