chore(cli): update eslint config and prettier codes

This commit is contained in:
陈嘉涵
2020-01-19 11:42:22 +08:00
parent 633e9cf59d
commit 1691451813
52 changed files with 383 additions and 363 deletions
+11 -11
View File
@@ -15,38 +15,38 @@ module.exports = function(api?: ConfigAPI) {
'@babel/preset-env',
{
loose: true,
modules: useESModules ? false : 'commonjs'
}
modules: useESModules ? false : 'commonjs',
},
],
[
'@vue/babel-preset-jsx',
{
functional: false
}
functional: false,
},
],
'@babel/preset-typescript'
'@babel/preset-typescript',
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
corejs: false,
useESModules
}
useESModules,
},
],
[
'import',
{
libraryName: 'vant',
libraryDirectory: useESModules ? 'es' : 'lib',
style: true
style: true,
},
'vant'
'vant',
],
'@babel/plugin-transform-object-assign',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator'
]
'@babel/plugin-proposal-nullish-coalescing-operator',
],
};
};
+5 -5
View File
@@ -4,26 +4,26 @@ import {
ROOT,
JEST_SETUP_FILE,
JEST_FILE_MOCK_FILE,
JEST_STYLE_MOCK_FILE
JEST_STYLE_MOCK_FILE,
} from '../common/constant';
const DEFAULT_CONFIG = {
moduleNameMapper: {
'\\.(css|less|scss)$': JEST_STYLE_MOCK_FILE,
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': JEST_FILE_MOCK_FILE
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': JEST_FILE_MOCK_FILE,
},
setupFilesAfterEnv: [JEST_SETUP_FILE],
moduleFileExtensions: ['js', 'jsx', 'vue', 'ts', 'tsx'],
transform: {
'\\.(vue)$': 'vue-jest',
'\\.(js|jsx|ts|tsx)$': 'babel-jest'
'\\.(js|jsx|ts|tsx)$': 'babel-jest',
},
transformIgnorePatterns: ['/node_modules/(?!(@vant/cli))/'],
snapshotSerializers: ['jest-serializer-vue'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx,vue}', '!**/demo/**'],
coverageReporters: ['html', 'lcov', 'text-summary'],
coverageDirectory: './test/coverage'
coverageDirectory: './test/coverage',
};
function readRootConfig() {
@@ -38,5 +38,5 @@ function readRootConfig() {
module.exports = {
...DEFAULT_CONFIG,
...readRootConfig()
...readRootConfig(),
};
@@ -7,20 +7,20 @@ type PostcssConfig = object & {
function mergePostcssConfig(config1: PostcssConfig, config2: PostcssConfig) {
const plugins = {
...config1.plugins,
...config2.plugins
...config2.plugins,
};
return {
...config1,
...config2,
plugins
plugins,
};
}
const DEFAULT_CONFIG = {
plugins: {
autoprefixer: {}
}
autoprefixer: {},
},
};
module.exports = mergePostcssConfig(DEFAULT_CONFIG, getPostcssConfig());
+26 -26
View File
@@ -6,14 +6,14 @@ import {
CACHE_DIR,
STYLE_EXTS,
SCRIPT_EXTS,
POSTCSS_CONFIG_FILE
POSTCSS_CONFIG_FILE,
} from '../common/constant';
const CACHE_LOADER = {
loader: 'cache-loader',
options: {
cacheDirectory: CACHE_DIR
}
cacheDirectory: CACHE_DIR,
},
};
const CSS_LOADERS = [
@@ -23,16 +23,16 @@ const CSS_LOADERS = [
loader: 'postcss-loader',
options: {
config: {
path: POSTCSS_CONFIG_FILE
}
}
}
path: POSTCSS_CONFIG_FILE,
},
},
},
];
export const baseConfig = {
mode: 'development',
resolve: {
extensions: [...SCRIPT_EXTS, ...STYLE_EXTS]
extensions: [...SCRIPT_EXTS, ...STYLE_EXTS],
},
module: {
rules: [
@@ -44,26 +44,26 @@ export const baseConfig = {
loader: 'vue-loader',
options: {
compilerOptions: {
preserveWhitespace: false
}
}
}
]
preserveWhitespace: false,
},
},
},
],
},
{
test: /\.(js|ts|jsx|tsx)$/,
exclude: /node_modules\/(?!(@vant\/cli))/,
use: [CACHE_LOADER, 'babel-loader']
use: [CACHE_LOADER, 'babel-loader'],
},
{
test: /\.css$/,
sideEffects: true,
use: CSS_LOADERS
use: CSS_LOADERS,
},
{
test: /\.less$/,
sideEffects: true,
use: [...CSS_LOADERS, 'less-loader']
use: [...CSS_LOADERS, 'less-loader'],
},
{
test: /\.scss$/,
@@ -73,22 +73,22 @@ export const baseConfig = {
{
loader: 'sass-loader',
options: {
implementation: sass
}
}
]
implementation: sass,
},
},
],
},
{
test: /\.md$/,
use: [CACHE_LOADER, 'vue-loader', '@vant/markdown-loader']
}
]
use: [CACHE_LOADER, 'vue-loader', '@vant/markdown-loader'],
},
],
},
plugins: [
new VueLoaderPlugin(),
new FriendlyErrorsPlugin({
clearConsole: false,
logLevel: 'WARNING'
})
]
logLevel: 'WARNING',
}),
],
};
@@ -14,7 +14,7 @@ export function getPackageConfig(isMinify: boolean) {
{
mode: 'production',
entry: {
[name]: join(ES_DIR, 'index.js')
[name]: join(ES_DIR, 'index.js'),
},
stats: 'none',
output: {
@@ -24,20 +24,20 @@ export function getPackageConfig(isMinify: boolean) {
filename: isMinify ? '[name].min.js' : '[name].js',
umdNamedDefine: true,
// https://github.com/webpack/webpack/issues/6522
globalObject: "typeof self !== 'undefined' ? self : this"
globalObject: "typeof self !== 'undefined' ? self : this",
},
externals: {
vue: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
amd: 'vue',
},
},
performance: false,
optimization: {
minimize: isMinify
}
minimize: isMinify,
},
},
getWebpackConfig()
);
@@ -10,7 +10,7 @@ import { VantCliSitePlugin } from '../compiler/vant-cli-site-plugin';
import {
GREEN,
SITE_MODILE_SHARED_FILE,
SITE_DESKTOP_SHARED_FILE
SITE_DESKTOP_SHARED_FILE,
} from '../common/constant';
export function getSiteDevBaseConfig() {
@@ -43,7 +43,7 @@ export function getSiteDevBaseConfig() {
return merge(baseConfig as any, {
entry: {
'site-desktop': [join(__dirname, '../../site/desktop/main.js')],
'site-mobile': [join(__dirname, '../../site/mobile/main.js')]
'site-mobile': [join(__dirname, '../../site/mobile/main.js')],
},
devServer: {
port: 8080,
@@ -51,16 +51,16 @@ export function getSiteDevBaseConfig() {
host: '0.0.0.0',
stats: 'errors-only',
publicPath: '/',
disableHostCheck: true
disableHostCheck: true,
},
resolve: {
alias: {
'site-mobile-shared': SITE_MODILE_SHARED_FILE,
'site-desktop-shared': SITE_DESKTOP_SHARED_FILE
}
'site-desktop-shared': SITE_DESKTOP_SHARED_FILE,
},
},
output: {
chunkFilename: '[name].js'
chunkFilename: '[name].js',
},
optimization: {
splitChunks: {
@@ -69,15 +69,15 @@ export function getSiteDevBaseConfig() {
chunks: 'all',
minChunks: 2,
minSize: 0,
name: 'chunks'
}
}
}
name: 'chunks',
},
},
},
},
plugins: [
new WebpackBar({
name: 'Vant Cli',
color: GREEN
color: GREEN,
}),
new VantCliSitePlugin(),
new HtmlWebpackPlugin({
@@ -87,7 +87,7 @@ export function getSiteDevBaseConfig() {
chunks: ['chunks', 'site-desktop'],
template: join(__dirname, '../../site/desktop/index.html'),
filename: 'index.html',
baiduAnalytics
baiduAnalytics,
}),
new HtmlWebpackPlugin({
title,
@@ -96,9 +96,9 @@ export function getSiteDevBaseConfig() {
chunks: ['chunks', 'site-mobile'],
template: join(__dirname, '../../site/mobile/index.html'),
filename: 'mobile.html',
baiduAnalytics
})
]
baiduAnalytics,
}),
],
});
}
@@ -18,8 +18,8 @@ export function getSitePrdConfig() {
publicPath,
path: outputDir,
filename: '[name].[hash:8].js',
chunkFilename: 'async_[name].[chunkhash:8].js'
}
chunkFilename: 'async_[name].[chunkhash:8].js',
},
},
getWebpackConfig()
);