feat(cli): support custom webpack config
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { join } from 'path';
|
||||
import merge from 'webpack-merge';
|
||||
import { join } from 'path';
|
||||
import { baseConfig } from './webpack.base';
|
||||
import { getWebpackConfig } from '../common';
|
||||
import { LIB_DIR, DIST_DIR, CONFIG_FILE } from '../common/constant';
|
||||
|
||||
// eslint-disable-next-line
|
||||
@@ -8,32 +9,36 @@ const config = require(CONFIG_FILE);
|
||||
const { name } = config;
|
||||
|
||||
export function packageConfig(isMinify: boolean) {
|
||||
return merge(baseConfig as any, {
|
||||
mode: 'production',
|
||||
entry: {
|
||||
[name]: join(DIST_DIR, 'index.js')
|
||||
},
|
||||
stats: 'none',
|
||||
output: {
|
||||
path: LIB_DIR,
|
||||
library: name,
|
||||
libraryTarget: 'umd',
|
||||
filename: isMinify ? '[name].min.js' : '[name].js',
|
||||
umdNamedDefine: true,
|
||||
// https://github.com/webpack/webpack/issues/6522
|
||||
globalObject: "typeof self !== 'undefined' ? self : this"
|
||||
},
|
||||
externals: {
|
||||
vue: {
|
||||
root: 'Vue',
|
||||
commonjs: 'vue',
|
||||
commonjs2: 'vue',
|
||||
amd: 'vue'
|
||||
return merge(
|
||||
baseConfig as any,
|
||||
{
|
||||
mode: 'production',
|
||||
entry: {
|
||||
[name]: join(DIST_DIR, 'index.js')
|
||||
},
|
||||
stats: 'none',
|
||||
output: {
|
||||
path: LIB_DIR,
|
||||
library: name,
|
||||
libraryTarget: 'umd',
|
||||
filename: isMinify ? '[name].min.js' : '[name].js',
|
||||
umdNamedDefine: true,
|
||||
// https://github.com/webpack/webpack/issues/6522
|
||||
globalObject: "typeof self !== 'undefined' ? self : this"
|
||||
},
|
||||
externals: {
|
||||
vue: {
|
||||
root: 'Vue',
|
||||
commonjs: 'vue',
|
||||
commonjs2: 'vue',
|
||||
amd: 'vue'
|
||||
}
|
||||
},
|
||||
performance: false,
|
||||
optimization: {
|
||||
minimize: isMinify
|
||||
}
|
||||
},
|
||||
performance: false,
|
||||
optimization: {
|
||||
minimize: isMinify
|
||||
}
|
||||
});
|
||||
getWebpackConfig()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,53 +3,58 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||
import { join } from 'path';
|
||||
import { baseConfig } from './webpack.base';
|
||||
import { CONFIG_FILE } from '../common/constant';
|
||||
import { getWebpackConfig } from '../common';
|
||||
|
||||
// eslint-disable-next-line
|
||||
const config = require(CONFIG_FILE);
|
||||
const title = `${config.title} - ${config.description}`;
|
||||
|
||||
export const siteDevConfig = merge(baseConfig as any, {
|
||||
entry: {
|
||||
'site-desktop': join(__dirname, '../../site/desktop/main.js'),
|
||||
'site-mobile': join(__dirname, '../../site/mobile/main.js')
|
||||
},
|
||||
devServer: {
|
||||
open: true,
|
||||
host: '0.0.0.0',
|
||||
stats: 'errors-only',
|
||||
disableHostCheck: true,
|
||||
},
|
||||
output: {
|
||||
path: join(__dirname, '../../site/dist'),
|
||||
publicPath: '/',
|
||||
chunkFilename: 'async_[name].js'
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
chunks: {
|
||||
chunks: 'all',
|
||||
minChunks: 2,
|
||||
minSize: 0,
|
||||
name: 'chunks'
|
||||
export const siteDevConfig = merge(
|
||||
baseConfig as any,
|
||||
{
|
||||
entry: {
|
||||
'site-desktop': join(__dirname, '../../site/desktop/main.js'),
|
||||
'site-mobile': join(__dirname, '../../site/mobile/main.js')
|
||||
},
|
||||
devServer: {
|
||||
open: true,
|
||||
host: '0.0.0.0',
|
||||
stats: 'errors-only',
|
||||
disableHostCheck: true
|
||||
},
|
||||
output: {
|
||||
path: join(__dirname, '../../site/dist'),
|
||||
publicPath: '/',
|
||||
chunkFilename: 'async_[name].js'
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
chunks: {
|
||||
chunks: 'all',
|
||||
minChunks: 2,
|
||||
minSize: 0,
|
||||
name: 'chunks'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: config.logo,
|
||||
chunks: ['chunks', 'site-desktop'],
|
||||
template: join(__dirname, '../../site/desktop/index.html'),
|
||||
filename: 'index.html'
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: config.logo,
|
||||
chunks: ['chunks', 'site-mobile'],
|
||||
template: join(__dirname, '../../site/mobile/index.html'),
|
||||
filename: 'mobile.html'
|
||||
})
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: config.logo,
|
||||
chunks: ['chunks', 'site-desktop'],
|
||||
template: join(__dirname, '../../site/desktop/index.html'),
|
||||
filename: 'index.html'
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: config.logo,
|
||||
chunks: ['chunks', 'site-mobile'],
|
||||
template: join(__dirname, '../../site/mobile/index.html'),
|
||||
filename: 'mobile.html'
|
||||
})
|
||||
]
|
||||
});
|
||||
getWebpackConfig()
|
||||
);
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import { join } from 'path';
|
||||
import merge from 'webpack-merge';
|
||||
import { join } from 'path';
|
||||
import { siteDevConfig } from './webpack.site.dev';
|
||||
import { getWebpackConfig } from '../common';
|
||||
|
||||
export const sitePrdConfig = merge(siteDevConfig, {
|
||||
mode: 'production',
|
||||
output: {
|
||||
path: join(__dirname, '../../site/dist'),
|
||||
publicPath: 'https://b.yzcdn.cn/vant/',
|
||||
filename: '[name].[hash:8].js',
|
||||
chunkFilename: 'async_[name].[chunkhash:8].js'
|
||||
}
|
||||
});
|
||||
export const sitePrdConfig = merge(
|
||||
siteDevConfig,
|
||||
{
|
||||
mode: 'production',
|
||||
output: {
|
||||
path: join(__dirname, '../../site/dist'),
|
||||
publicPath: 'https://b.yzcdn.cn/vant/',
|
||||
filename: '[name].[hash:8].js',
|
||||
chunkFilename: 'async_[name].[chunkhash:8].js'
|
||||
}
|
||||
},
|
||||
getWebpackConfig()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user