chore(@vant/cli): remove webpack related deps
This commit is contained in:
@@ -27,15 +27,6 @@ module.exports = function (api?: ConfigAPI, options: PresetOption = {}) {
|
||||
require('../compiler/babel-preset-vue-ts'),
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('babel-plugin-import'),
|
||||
{
|
||||
libraryName: 'vant',
|
||||
libraryDirectory: useESModules ? 'es' : 'lib',
|
||||
style: true,
|
||||
},
|
||||
'vant',
|
||||
],
|
||||
[
|
||||
require.resolve('@vue/babel-plugin-jsx'),
|
||||
{
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
import sass from 'sass';
|
||||
import webpack from 'webpack';
|
||||
import { VueLoaderPlugin } from 'vue-loader';
|
||||
import { join } from 'path';
|
||||
import { consola } from '../common/logger';
|
||||
import { existsSync } from 'fs';
|
||||
import { WebpackConfig } from '../common/types';
|
||||
import {
|
||||
CWD,
|
||||
STYLE_EXTS,
|
||||
SCRIPT_EXTS,
|
||||
POSTCSS_CONFIG_FILE,
|
||||
} from '../common/constant';
|
||||
|
||||
const CSS_LOADERS = [
|
||||
require.resolve('style-loader'),
|
||||
require.resolve('css-loader'),
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
postcssOptions: require(POSTCSS_CONFIG_FILE),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const VUE_LOADER = {
|
||||
loader: require.resolve('vue-loader'),
|
||||
options: {
|
||||
compilerOptions: {
|
||||
preserveWhitespace: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const plugins = [
|
||||
new webpack.DefinePlugin({
|
||||
__VUE_OPTIONS_API__: 'true',
|
||||
__VUE_PROD_DEVTOOLS__: 'false',
|
||||
}),
|
||||
new VueLoaderPlugin(),
|
||||
];
|
||||
|
||||
const tsconfigPath = join(CWD, 'tsconfig.json');
|
||||
if (existsSync(tsconfigPath)) {
|
||||
const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
|
||||
plugins.push(
|
||||
new ForkTsCheckerPlugin({
|
||||
typescript: {
|
||||
extensions: {
|
||||
vue: {
|
||||
enabled: true,
|
||||
compiler: '@vue/compiler-sfc',
|
||||
},
|
||||
},
|
||||
},
|
||||
logger: {
|
||||
issues: {
|
||||
// skip info message
|
||||
log() {},
|
||||
warn(message: string) {
|
||||
consola.warn(message);
|
||||
},
|
||||
error(message: string) {
|
||||
consola.error(message);
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const baseConfig: WebpackConfig = {
|
||||
mode: 'development',
|
||||
resolve: {
|
||||
extensions: [...SCRIPT_EXTS, ...STYLE_EXTS],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: [VUE_LOADER],
|
||||
},
|
||||
{
|
||||
test: /\.(js|ts|jsx|tsx)$/,
|
||||
exclude: /node_modules\/(?!(@vant\/cli))/,
|
||||
use: [require.resolve('babel-loader')],
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
sideEffects: true,
|
||||
use: CSS_LOADERS,
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
sideEffects: true,
|
||||
use: [...CSS_LOADERS, require.resolve('less-loader')],
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
sideEffects: true,
|
||||
use: [
|
||||
...CSS_LOADERS,
|
||||
{
|
||||
loader: require.resolve('sass-loader'),
|
||||
options: {
|
||||
implementation: sass,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.md$/,
|
||||
use: [VUE_LOADER, require.resolve('@vant/markdown-loader')],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins,
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
buildDependencies: {
|
||||
config: [__filename],
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,109 +0,0 @@
|
||||
import WebpackBar from 'webpackbar';
|
||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||
import { get } from 'lodash';
|
||||
import { join } from 'path';
|
||||
import { merge } from 'webpack-merge';
|
||||
import { baseConfig } from './webpack.base';
|
||||
import { WebpackConfig } from '../common/types';
|
||||
import { getVantConfig, getWebpackConfig } from '../common';
|
||||
import {
|
||||
GREEN,
|
||||
SITE_MOBILE_SHARED_FILE,
|
||||
SITE_DESKTOP_SHARED_FILE,
|
||||
} from '../common/constant';
|
||||
|
||||
export function getSiteDevBaseConfig(): WebpackConfig {
|
||||
const vantConfig = getVantConfig();
|
||||
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
|
||||
|
||||
function getSiteConfig() {
|
||||
const siteConfig = vantConfig.site;
|
||||
|
||||
if (siteConfig.locales) {
|
||||
return siteConfig.locales[siteConfig.defaultLang || 'en-US'];
|
||||
}
|
||||
|
||||
return siteConfig;
|
||||
}
|
||||
|
||||
function getTitle(config: { title: string; description?: string }) {
|
||||
let { title } = config;
|
||||
|
||||
if (config.description) {
|
||||
title += ` - ${config.description}`;
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
const siteConfig = getSiteConfig();
|
||||
const title = getTitle(siteConfig);
|
||||
const { htmlPluginOptions } = vantConfig.site;
|
||||
|
||||
return merge(baseConfig as any, {
|
||||
entry: {
|
||||
'site-desktop': [join(__dirname, '../../site/desktop/main.js')],
|
||||
'site-mobile': [join(__dirname, '../../site/mobile/main.js')],
|
||||
},
|
||||
devServer: {
|
||||
port: 8080,
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: 'all',
|
||||
devMiddleware: {
|
||||
stats: 'errors-only',
|
||||
publicPath: '/',
|
||||
},
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'site-mobile-shared': SITE_MOBILE_SHARED_FILE,
|
||||
'site-desktop-shared': SITE_DESKTOP_SHARED_FILE,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
chunkFilename: '[name].js',
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
chunks: {
|
||||
chunks: 'all',
|
||||
minChunks: 2,
|
||||
minSize: 0,
|
||||
name: 'chunks',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new WebpackBar({
|
||||
name: 'Vant Cli',
|
||||
color: GREEN,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: siteConfig.logo,
|
||||
description: siteConfig.description,
|
||||
chunks: ['chunks', 'site-desktop'],
|
||||
template: join(__dirname, '../../site/desktop/index.html'),
|
||||
filename: 'index.html',
|
||||
baiduAnalytics,
|
||||
...htmlPluginOptions,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
title,
|
||||
logo: siteConfig.logo,
|
||||
description: siteConfig.description,
|
||||
chunks: ['chunks', 'site-mobile'],
|
||||
template: join(__dirname, '../../site/mobile/index.html'),
|
||||
filename: 'mobile.html',
|
||||
baiduAnalytics,
|
||||
...htmlPluginOptions,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export function getSiteDevConfig(): WebpackConfig {
|
||||
return getWebpackConfig(getSiteDevBaseConfig());
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { merge } from 'webpack-merge';
|
||||
import { get } from 'lodash';
|
||||
import { WebpackConfig } from '../common/types';
|
||||
import { getVantConfig, getWebpackConfig } from '../common';
|
||||
import { getSiteDevBaseConfig } from './webpack.site.dev';
|
||||
import { SITE_DIST_DIR } from '../common/constant';
|
||||
|
||||
const vantConfig = getVantConfig();
|
||||
const outputDir = get(vantConfig, 'build.site.outputDir', SITE_DIST_DIR);
|
||||
const publicPath = get(vantConfig, 'build.site.publicPath', '/');
|
||||
|
||||
export function getSitePrdConfig(): WebpackConfig {
|
||||
return getWebpackConfig(
|
||||
merge(getSiteDevBaseConfig(), {
|
||||
mode: 'production',
|
||||
stats: 'none',
|
||||
performance: {
|
||||
maxAssetSize: 5 * 1024 * 1024,
|
||||
maxEntrypointSize: 5 * 1024 * 1024,
|
||||
},
|
||||
output: {
|
||||
publicPath,
|
||||
path: outputDir,
|
||||
filename: '[name].[contenthash:8].js',
|
||||
chunkFilename: 'async_[name].[contenthash:8].js',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user