chore(@vant/cli): remove webpack related deps
This commit is contained in:
@@ -18,7 +18,7 @@ const program = new Command();
|
||||
|
||||
program.version(`@vant/cli ${cliVersion}`);
|
||||
|
||||
program.command('dev').description('Run webpack dev server').action(dev);
|
||||
program.command('dev').description('Run dev server').action(dev);
|
||||
|
||||
program.command('lint').description('Run eslint and stylelint').action(lint);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ export const VETUR_DIR = join(ROOT, 'vetur');
|
||||
export const SITE_DIST_DIR = join(ROOT, 'site');
|
||||
export const VANT_CONFIG_FILE = join(ROOT, 'vant.config.js');
|
||||
export const PACKAGE_JSON_FILE = join(ROOT, 'package.json');
|
||||
export const ROOT_WEBPACK_CONFIG_FILE = join(ROOT, 'webpack.config.js');
|
||||
export const ROOT_POSTCSS_CONFIG_FILE = join(ROOT, 'postcss.config.js');
|
||||
export const CACHE_DIR = join(ROOT, 'node_modules/.cache');
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ import {
|
||||
readFileSync,
|
||||
outputFileSync,
|
||||
} from 'fs-extra';
|
||||
import { merge } from 'webpack-merge';
|
||||
import { SRC_DIR, getVantConfig, ROOT_WEBPACK_CONFIG_FILE } from './constant';
|
||||
import { WebpackConfig } from './types';
|
||||
import { SRC_DIR, getVantConfig } from './constant';
|
||||
|
||||
export const EXT_REGEXP = /\.\w+$/;
|
||||
export const SFC_REGEXP = /\.(vue)$/;
|
||||
@@ -102,22 +100,6 @@ export function normalizePath(path: string): string {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
export function getWebpackConfig(defaultConfig: WebpackConfig): WebpackConfig {
|
||||
if (existsSync(ROOT_WEBPACK_CONFIG_FILE)) {
|
||||
const config = require(ROOT_WEBPACK_CONFIG_FILE);
|
||||
|
||||
// 如果是函数形式,可能并不仅仅是添加额外的处理流程,而是在原有流程上进行修改
|
||||
// 比如修改markdown-loader,添加options.enableMetaData
|
||||
if (typeof config === 'function') {
|
||||
return merge(defaultConfig, config(defaultConfig));
|
||||
}
|
||||
|
||||
return merge(defaultConfig, config);
|
||||
}
|
||||
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
export type ModuleEnv = 'esmodule' | 'commonjs';
|
||||
export type NodeEnv = 'production' | 'development' | 'test';
|
||||
export type BuildTarget = 'site' | 'package';
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import type Webpack from 'webpack';
|
||||
|
||||
export type WebpackConfig = Webpack.Configuration & {
|
||||
devServer?: any;
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
Vendored
-3
@@ -4,10 +4,7 @@ declare module 'sass';
|
||||
declare module 'execa';
|
||||
declare module 'hash-sum';
|
||||
declare module 'clean-css';
|
||||
declare module 'webpackbar';
|
||||
declare module 'release-it';
|
||||
declare module 'webpack-dev-server';
|
||||
declare module 'html-webpack-plugin';
|
||||
declare module 'conventional-changelog';
|
||||
declare module '@vant/markdown-vetur';
|
||||
declare module '@babel/helper-plugin-utils';
|
||||
|
||||
Reference in New Issue
Block a user