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