mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): auto install all components
This commit is contained in:
parent
fac1a85c87
commit
e4f934dfde
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import VanDoc from './components';
|
import VanDoc from './components';
|
||||||
import { config } from '../../dist/desktop-config';
|
import { config } from 'desktop-entry';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -5,6 +5,10 @@ import { routes } from './router';
|
|||||||
import { isMobile } from '../common';
|
import { isMobile } from '../common';
|
||||||
import '../common/iframe-router';
|
import '../common/iframe-router';
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
Vue.config.productionTip = false;
|
||||||
|
}
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import { documents } from '../../dist/desktop-config';
|
import { documents } from 'desktop-entry';
|
||||||
|
|
||||||
const routes = [];
|
const routes = [];
|
||||||
const names = Object.keys(documents);
|
const names = Object.keys(documents);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { config } from '../../../dist/mobile-config';
|
import { config } from 'mobile-entry';
|
||||||
import DemoHomeNav from './DemoHomeNav';
|
import DemoHomeNav from './DemoHomeNav';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -7,6 +7,10 @@ import App from './App';
|
|||||||
import '@vant/touch-emulator';
|
import '@vant/touch-emulator';
|
||||||
import '../common/iframe-router';
|
import '../common/iframe-router';
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
Vue.config.productionTip = false;
|
||||||
|
}
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
Vue.component(DemoBlock.name, DemoBlock);
|
Vue.component(DemoBlock.name, DemoBlock);
|
||||||
Vue.component(DemoSection.name, DemoSection);
|
Vue.component(DemoSection.name, DemoSection);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import DemoHome from './components/DemoHome';
|
import DemoHome from './components/DemoHome';
|
||||||
import { demos } from '../../dist/mobile-config';
|
import { demos } from 'mobile-entry';
|
||||||
|
|
||||||
const routes = [];
|
const routes = [];
|
||||||
const names = Object.keys(demos);
|
const names = Object.keys(demos);
|
||||||
|
@ -3,8 +3,9 @@ import WebpackDevServer from 'webpack-dev-server';
|
|||||||
import { getPort } from 'portfinder';
|
import { getPort } from 'portfinder';
|
||||||
import { clean } from '../commands/clean';
|
import { clean } from '../commands/clean';
|
||||||
import { siteDevConfig } from '../config/webpack.site.dev';
|
import { siteDevConfig } from '../config/webpack.site.dev';
|
||||||
import { genMobileConfig } from '../compiler/gen-mobile-config';
|
import { genPackageEntry } from '../compiler/gen-package-entry';
|
||||||
import { genDesktopConfig } from '../compiler/gen-desktop-config';
|
import { genMobileEntry } from '../compiler/gen-mobile-entry';
|
||||||
|
import { genDesktopEntry } from '../compiler/gen-desktop-entry';
|
||||||
|
|
||||||
function runWebpack() {
|
function runWebpack() {
|
||||||
const server = new WebpackDevServer(
|
const server = new WebpackDevServer(
|
||||||
@ -33,7 +34,8 @@ function runWebpack() {
|
|||||||
|
|
||||||
export function dev() {
|
export function dev() {
|
||||||
clean();
|
clean();
|
||||||
genMobileConfig();
|
genPackageEntry();
|
||||||
genDesktopConfig();
|
genMobileEntry();
|
||||||
|
genDesktopEntry();
|
||||||
runWebpack();
|
runWebpack();
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
|
|||||||
export const DIST_DIR = join(__dirname, '../../dist');
|
export const DIST_DIR = join(__dirname, '../../dist');
|
||||||
export const CONFIG_DIR = join(__dirname, '../config');
|
export const CONFIG_DIR = join(__dirname, '../config');
|
||||||
|
|
||||||
export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'index.js');
|
export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'package-entry.js');
|
||||||
export const MOBILE_CONFIG_FILE = join(DIST_DIR, 'mobile-config.js');
|
export const MOBILE_ENTRY_FILE = join(DIST_DIR, 'mobile-entry.js');
|
||||||
export const DESKTOP_CONFIG_FILE = join(DIST_DIR, 'desktop-config.js');
|
export const DESKTOP_ENTRY_FILE = join(DIST_DIR, 'desktop-entry.js');
|
||||||
|
|
||||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||||
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js');
|
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js');
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
DOCS_DIR,
|
DOCS_DIR,
|
||||||
DIST_DIR,
|
DIST_DIR,
|
||||||
CONFIG_FILE,
|
CONFIG_FILE,
|
||||||
DESKTOP_CONFIG_FILE
|
DESKTOP_ENTRY_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
type DocumentItem = {
|
type DocumentItem = {
|
||||||
@ -58,7 +58,7 @@ function genExportConfig() {
|
|||||||
return 'export { config };';
|
return 'export { config };';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genDesktopConfig() {
|
export function genDesktopEntry() {
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
const documents = resolveDocuments(components);
|
const documents = resolveDocuments(components);
|
||||||
|
|
||||||
@ -69,5 +69,5 @@ ${genExportConfig()}
|
|||||||
${genExportDocuments(documents)}
|
${genExportDocuments(documents)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
writeFileSync(DESKTOP_CONFIG_FILE, code);
|
writeFileSync(DESKTOP_ENTRY_FILE, code);
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import { decamelize, pascalize, removeExt, getComponents } from '../common';
|
|||||||
import {
|
import {
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
DIST_DIR,
|
DIST_DIR,
|
||||||
MOBILE_CONFIG_FILE,
|
MOBILE_ENTRY_FILE,
|
||||||
CONFIG_FILE
|
CONFIG_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
@ -13,6 +13,14 @@ type DemoItem = {
|
|||||||
path: string;
|
path: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function genInstall() {
|
||||||
|
return `import Vue from 'vue';
|
||||||
|
import PackageEntry from './package-entry';
|
||||||
|
|
||||||
|
Vue.use(PackageEntry);
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
function genImports(demos: DemoItem[]) {
|
function genImports(demos: DemoItem[]) {
|
||||||
return demos
|
return demos
|
||||||
.map(item => {
|
.map(item => {
|
||||||
@ -49,13 +57,13 @@ function genCode(components: string[]) {
|
|||||||
}))
|
}))
|
||||||
.filter(item => existsSync(item.path));
|
.filter(item => existsSync(item.path));
|
||||||
|
|
||||||
return `${genImports(demos)}\n\n${genExports(demos)}\n${genConfig(demos)}\n`;
|
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(demos)}\n${genConfig(demos)}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genMobileConfig() {
|
export function genMobileEntry() {
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
const code = genCode(components);
|
const code = genCode(components);
|
||||||
|
|
||||||
ensureDirSync(DIST_DIR);
|
ensureDirSync(DIST_DIR);
|
||||||
writeFileSync(MOBILE_CONFIG_FILE, code);
|
writeFileSync(MOBILE_ENTRY_FILE, code);
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ const components = [
|
|||||||
${names.join(',\n ')}
|
${names.join(',\n ')}
|
||||||
];
|
];
|
||||||
|
|
||||||
function install() {
|
function install(Vue) {
|
||||||
components.forEach(item => {
|
components.forEach(item => {
|
||||||
if (item.install) {
|
if (item.install) {
|
||||||
Vue.use(Component);
|
Vue.use(Component);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import merge from 'webpack-merge';
|
import merge from 'webpack-merge';
|
||||||
import { join } from 'path';
|
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { getWebpackConfig } from '../common';
|
import { getWebpackConfig } from '../common';
|
||||||
import { LIB_DIR, DIST_DIR, CONFIG_FILE } from '../common/constant';
|
import { LIB_DIR, CONFIG_FILE, PACKAGE_ENTRY_FILE } from '../common/constant';
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const config = require(CONFIG_FILE);
|
const config = require(CONFIG_FILE);
|
||||||
@ -14,7 +13,7 @@ export function packageConfig(isMinify: boolean) {
|
|||||||
{
|
{
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
entry: {
|
entry: {
|
||||||
[name]: join(DIST_DIR, 'index.js')
|
[name]: PACKAGE_ENTRY_FILE
|
||||||
},
|
},
|
||||||
stats: 'none',
|
stats: 'none',
|
||||||
output: {
|
output: {
|
||||||
|
@ -2,7 +2,7 @@ import merge from 'webpack-merge';
|
|||||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { CONFIG_FILE } from '../common/constant';
|
import { CONFIG_FILE, MOBILE_ENTRY_FILE, DESKTOP_ENTRY_FILE } from '../common/constant';
|
||||||
import { getWebpackConfig } from '../common';
|
import { getWebpackConfig } from '../common';
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
@ -22,6 +22,12 @@ export const siteDevConfig = merge(
|
|||||||
stats: 'errors-only',
|
stats: 'errors-only',
|
||||||
disableHostCheck: true
|
disableHostCheck: true
|
||||||
},
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'mobile-entry': MOBILE_ENTRY_FILE,
|
||||||
|
'desktop-entry': DESKTOP_ENTRY_FILE
|
||||||
|
}
|
||||||
|
},
|
||||||
output: {
|
output: {
|
||||||
path: join(__dirname, '../../site/dist'),
|
path: join(__dirname, '../../site/dist'),
|
||||||
publicPath: '/',
|
publicPath: '/',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user