🌈 An enterprise-class UI components based on Ant Design and Vue. 🐜
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
5.3 KiB

const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const deepAssign = require('deep-assign');
const chalk = require('chalk');
const postcssConfig = require('./postcssConfig');
const distFileBaseName = 'antd';
module.exports = function(modules) {
const pkg = require(path.join(process.cwd(), 'package.json'));
const babelConfig = require('./getBabelCommonConfig')(modules || false);
7 years ago
const pluginImportOptions = [
{
style: true,
libraryName: 'antd',
libraryDirectory: 'components',
},
];
7 years ago
// if (distFileBaseName !== 'antd') { pluginImportOptions.push({ style:
// 'css', libraryDirectory: 'components', libraryName: 'antd', }) }
babelConfig.plugins.push([require.resolve('babel-plugin-import'), pluginImportOptions]);
7 years ago
const config = {
devtool: 'source-map',
output: {
path: path.join(process.cwd(), './dist/'),
filename: '[name].js',
},
resolve: {
modules: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: ['.js', '.jsx', '.vue', '.md', '.json'],
7 years ago
alias: {
vue$: 'vue/dist/vue.esm.js',
7 years ago
'@': process.cwd(),
},
},
node: [
'child_process',
'cluster',
'dgram',
'dns',
'fs',
'module',
'net',
'readline',
'repl',
'tls',
].reduce((acc, name) => Object.assign({}, acc, { [name]: 'empty' }), {}),
module: {
noParse: [/moment.js/],
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
use: [
{
loader: 'vue-loader',
options: {
loaders: {
js: [
{
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: ['transform-vue-jsx', 'transform-object-rest-spread'],
},
},
],
},
},
7 years ago
},
],
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: babelConfig,
},
{
7 years ago
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
7 years ago
loader: 'postcss-loader',
options: Object.assign({}, postcssConfig, { sourceMap: true }),
7 years ago
},
],
}),
},
{
7 years ago
test: /\.less$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
7 years ago
loader: 'postcss-loader',
options: Object.assign({}, postcssConfig, { sourceMap: true }),
},
{
7 years ago
loader: 'less-loader',
options: {
sourceMap: true,
},
},
],
}),
},
],
},
plugins: [
new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }),
7 years ago
new CaseSensitivePathsPlugin(),
new webpack.BannerPlugin(`
${distFileBaseName} v${pkg.version}
Copyright 2017-present, ant-design-vue.
7 years ago
All rights reserved.
`),
new webpack.ProgressPlugin((percentage, msg, addInfo) => {
const stream = process.stderr;
7 years ago
if (stream.isTTY && percentage < 0.71) {
stream.cursorTo(0);
stream.write(`📦 ${chalk.magenta(msg)} (${chalk.magenta(addInfo)})`);
stream.clearLine(1);
7 years ago
} else if (percentage === 1) {
console.log(chalk.green('\nwebpack: bundle build is now finished.'));
7 years ago
}
}),
],
};
7 years ago
if (process.env.RUN_ENV === 'PRODUCTION') {
const entry = ['./index'];
7 years ago
config.entry = {
[`${distFileBaseName}.min`]: entry,
};
7 years ago
config.externals = {
vue: {
root: 'Vue',
commonjs2: 'vue',
commonjs: 'vue',
amd: 'vue',
},
};
config.output.library = distFileBaseName;
config.output.libraryTarget = 'umd';
const uncompressedConfig = deepAssign({}, config);
config.plugins = config.plugins.concat([
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
output: {
ascii_only: true,
},
compress: {
warnings: false,
},
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.LoaderOptionsPlugin({ minimize: true }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
}),
]);
7 years ago
uncompressedConfig.entry = {
[distFileBaseName]: entry,
};
7 years ago
uncompressedConfig.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
);
7 years ago
return [config, uncompressedConfig];
7 years ago
}
return config;
};