feat(cli): build lib packed entry files

This commit is contained in:
陈嘉涵 2019-12-12 09:46:39 +08:00
parent 29e9e1c476
commit 5318f3bd3f
7 changed files with 43 additions and 42 deletions

View File

@ -41,9 +41,7 @@
"@types/webpack": "^4.41.0",
"@types/webpack-dev-server": "^3.9.0",
"@types/webpack-merge": "^4.1.5",
"vant": "^2.2.15",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
"vant": "^2.2.15"
},
"dependencies": {
"@babel/core": "^7.7.4",

View File

@ -20,6 +20,8 @@ import {
setNodeEnv,
setModuleEnv
} from '../common';
import { genPacakgeStyle } from '../compiler/gen-package-style';
import { CSS_LANG } from '../common/css';
const stepper = getStepper(10);
@ -112,15 +114,23 @@ async function buildPackageEntry() {
try {
const esEntryFile = join(ES_DIR, 'index.js');
const libEntryFile = join(LIB_DIR, 'index.js');
const styleEntryFile = join(LIB_DIR, `index.${CSS_LANG}`);
genPackageEntry({
outputPath: esEntryFile,
pathResolver: (path: string) => `./${relative(SRC_DIR, path)}`
});
genPacakgeStyle({
outputPath: styleEntryFile,
pathResolver: (path: string) => path.replace(SRC_DIR, '.')
});
setModuleEnv('commonjs');
await copy(esEntryFile, libEntryFile);
await compileJs(libEntryFile);
await compileStyle(styleEntryFile);
stepper.success('Build Package Entry');
} catch (err) {

View File

@ -1,26 +1,39 @@
import { join } from 'path';
import { replaceExt, smartOutputFile } from '../common';
import { smartOutputFile } from '../common';
import { CSS_LANG, getCssBaseFile } from '../common/css';
import {
SRC_DIR,
PACKAGE_STYLE_FILE,
STYPE_DEPS_JSON_FILE
} from '../common/constant';
import { SRC_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
export function genPacakgeStyle() {
type Options = {
outputPath: string;
pathResolver?: Function;
};
export function genPacakgeStyle(options: Options) {
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
const ext = '.' + CSS_LANG;
let content = '';
const baseFile = getCssBaseFile();
let baseFile = getCssBaseFile();
if (baseFile) {
if (options.pathResolver) {
baseFile = options.pathResolver(baseFile);
}
content += `@import "${baseFile}";\n`;
}
content += styleDepsJson.sequence
.map((name: string) => `@import "${join(SRC_DIR, `${name}/index${ext}`)}";`)
.map((name: string) => {
let path = join(SRC_DIR, `${name}/index${ext}`);
if (options.pathResolver) {
path = options.pathResolver(path);
}
return `@import "${path}";`;
})
.join('\n');
smartOutputFile(replaceExt(PACKAGE_STYLE_FILE, ext), content);
smartOutputFile(options.outputPath, content);
}

View File

@ -1,10 +1,12 @@
import { Compiler } from 'webpack';
import { replaceExt } from '../common';
import { CSS_LANG } from '../common/css';
import { genPackageEntry } from './gen-package-entry';
import { genPacakgeStyle } from './gen-package-style';
import { genSiteMobileShared } from './gen-site-mobile-shared';
import { genSiteDesktopShared } from './gen-site-desktop-shared';
import { genStyleDepsMap } from './gen-style-deps-map';
import { PACKAGE_ENTRY_FILE } from '../common/constant';
import { PACKAGE_ENTRY_FILE, PACKAGE_STYLE_FILE } from '../common/constant';
const PLUGIN_NAME = 'VantCliSitePlugin';
@ -20,7 +22,9 @@ export class VantCliSitePlugin {
genPackageEntry({
outputPath: PACKAGE_ENTRY_FILE
});
genPacakgeStyle();
genPacakgeStyle({
outputPath: replaceExt(PACKAGE_STYLE_FILE, `.${CSS_LANG}`)
});
genSiteMobileShared();
genSiteDesktopShared();
resolve();

View File

@ -1,14 +1,8 @@
module.exports = function(api: any) {
module.exports = function() {
const { BABEL_MODULE, NODE_ENV } = process.env;
const isTest = NODE_ENV === 'test';
const useESModules = BABEL_MODULE !== 'commonjs' && !isTest;
console.log('cache ??', useESModules, api);
if (api) {
console.log('never ed');
api.cache.never();
}
return {
presets: [
[

View File

@ -3538,11 +3538,6 @@ date-fns@^1.27.2:
resolved "https://registry.npm.taobao.org/date-fns/download/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha1-LnG/CxGRU9u0zE6I2epaz7UNwFw=
de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.npm.taobao.org/de-indent/download/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
integrity sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@ -5189,7 +5184,7 @@ hash.js@^1.0.0, hash.js@^1.0.3:
inherits "^2.0.3"
minimalistic-assert "^1.0.1"
he@1.2.x, he@^1.1.0:
he@1.2.x:
version "1.2.0"
resolved "https://registry.npm.taobao.org/he/download/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha1-hK5l+n6vsWX922FWauFLrwVmTw8=
@ -10924,24 +10919,11 @@ vue-style-loader@^4.1.0:
hash-sum "^1.0.2"
loader-utils "^1.0.2"
vue-template-compiler@^2.6.10:
version "2.6.10"
resolved "https://registry.npm.taobao.org/vue-template-compiler/download/vue-template-compiler-2.6.10.tgz#323b4f3495f04faa3503337a82f5d6507799c9cc"
integrity sha1-MjtPNJXwT6o1AzN6gvXWUHeZycw=
dependencies:
de-indent "^1.0.2"
he "^1.1.0"
vue-template-es2015-compiler@^1.9.0:
version "1.9.1"
resolved "https://registry.npm.taobao.org/vue-template-es2015-compiler/download/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825"
integrity sha1-HuO8mhbsv1EYvjNLsV+cRvgvWCU=
vue@^2.6.10:
version "2.6.10"
resolved "https://registry.npm.taobao.org/vue/download/vue-2.6.10.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue%2Fdownload%2Fvue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
integrity sha1-pysaQqTYKnIepDjRtr9V5mGVxjc=
w3c-hr-time@^1.0.1:
version "1.0.1"
resolved "https://registry.npm.taobao.org/w3c-hr-time/download/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"

View File

@ -47,7 +47,7 @@
</template>
<script>
import { ImagePreview } from '../..';
import ImagePreview from '..';
const images = [
'https://img.yzcdn.cn/vant/apple-1.jpg',