@goji/webpack-plugin
Advanced tools
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
exports.DEFAULT_OPTIONS = { | ||
@@ -8,0 +6,0 @@ maxDepth: 10, |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const webpack_1 = __importDefault(require("webpack")); | ||
const tslib_1 = require("tslib"); | ||
const webpack_1 = tslib_1.__importDefault(require("webpack")); | ||
const bridge_1 = require("./plugins/bridge"); | ||
@@ -14,6 +12,3 @@ const config_1 = require("./plugins/config"); | ||
constructor(options = {}) { | ||
this.options = { | ||
...constants_1.DEFAULT_OPTIONS, | ||
...options, | ||
}; | ||
this.options = Object.assign(Object.assign({}, constants_1.DEFAULT_OPTIONS), options); | ||
} | ||
@@ -25,2 +20,3 @@ apply(compiler) { | ||
'process.env.GOJI_COMPONENT_WHITELIST': JSON.stringify(options.unstable_componentWhitelist), | ||
'process.env.GOJI_MAX_DEPTH': JSON.stringify(options.maxDepth), | ||
}).apply(compiler); | ||
@@ -27,0 +23,0 @@ new bridge_1.GojiBridgeWebpackPlugin(options).apply(compiler); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const replace_ext_1 = __importDefault(require("replace-ext")); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const replace_ext_1 = tslib_1.__importDefault(require("replace-ext")); | ||
const transformExtension_1 = require("../utils/transformExtension"); | ||
@@ -9,0 +7,0 @@ class GojiBasedWebpackPlugin { |
@@ -12,5 +12,5 @@ import webpack from 'webpack'; | ||
private shouldInlineChildrenRender; | ||
private shouldUseFlattenBridge; | ||
private shouldUseSubtree; | ||
private useWrappedComponent; | ||
private renderFlattenBridge; | ||
private renderSubtreeBridge; | ||
private renderLeafTemplate; | ||
@@ -17,0 +17,0 @@ private renderChildrenRenderComponent; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const core_1 = require("@goji/core"); | ||
@@ -30,17 +28,19 @@ const components_1 = require("../utils/components"); | ||
} | ||
async renderTemplateToAsset(compilation, assetPath, templatePath, data) { | ||
const formattedAssetPath = this.transformExtForPath(assetPath); | ||
// skip existing asset | ||
if (compilation.assets[formattedAssetPath] !== undefined) { | ||
console.warn('skip existing asset', formattedAssetPath); | ||
return; | ||
} | ||
let content = await this.renderTemplate(templatePath, data); | ||
if (this.options.minimize) { | ||
content = minimize_1.minimize(content, path_1.default.extname(assetPath)); | ||
} | ||
compilation.assets[formattedAssetPath] = { | ||
source: () => content, | ||
size: () => content.length, | ||
}; | ||
renderTemplateToAsset(compilation, assetPath, templatePath, data) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const formattedAssetPath = this.transformExtForPath(assetPath); | ||
// skip existing asset | ||
if (compilation.assets[formattedAssetPath] !== undefined) { | ||
console.warn('skip existing asset', formattedAssetPath); | ||
return; | ||
} | ||
let content = yield this.renderTemplate(templatePath, data); | ||
if (this.options.minimize) { | ||
content = minimize_1.minimize(content, path_1.default.extname(assetPath)); | ||
} | ||
compilation.assets[formattedAssetPath] = { | ||
source: () => content, | ||
size: () => content.length, | ||
}; | ||
}); | ||
} | ||
@@ -54,3 +54,3 @@ shouldInlineChildrenRender() { | ||
} | ||
shouldUseFlattenBridge() { | ||
shouldUseSubtree() { | ||
const { target } = this.options; | ||
@@ -63,70 +63,82 @@ return target === 'wechat' || target === 'qq'; | ||
} | ||
async renderFlattenBridge(compilation) { | ||
const components = this.getRenderedComponents(); | ||
const { maxDepth } = this.options; | ||
for (let depth = 0; depth < maxDepth; depth += 1) { | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children${depth}.wxml`, 'children.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
renderSubtreeBridge(compilation) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
const { maxDepth } = this.options; | ||
for (let depth = 0; depth < maxDepth; depth += 1) { | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children${depth}.wxml`, 'children.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
}); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components${depth}.wxml`, 'components.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender: this.shouldInlineChildrenRender(), | ||
}); | ||
} | ||
}); | ||
} | ||
renderLeafTemplate(compilation) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/leaf-components.wxml`, `leaf-components.wxml.ejs`, { | ||
components: components.filter(c => c.isLeaf), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components${depth}.wxml`, 'components.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender: this.shouldInlineChildrenRender(), | ||
}); | ||
} | ||
} | ||
async renderLeafTemplate(compilation) { | ||
const components = this.getRenderedComponents(); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/leaf-components.wxml`, `leaf-components.wxml.ejs`, { | ||
components: components.filter(c => c.isLeaf), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
} | ||
async renderChildrenRenderComponent(compilation) { | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children-render.js`, 'children-render.js.ejs', {}); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children-render.json`, 'children-render.json.ejs', { | ||
relativePathToBridge: '.', | ||
components: this.getWhitelistedComponents(), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
renderChildrenRenderComponent(compilation) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/subtree.js`, 'subtree.js.ejs', {}); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/subtree.json`, 'subtree.json.ejs', { | ||
relativePathToBridge: '.', | ||
components: this.getWhitelistedComponents(), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/subtree.wxml`, 'subtree.wxml.ejs', {}); | ||
}); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children-render.wxml`, 'children-render.wxml.ejs', {}); | ||
} | ||
async renderComponentTemplate(compilation, inlineChildrenRender) { | ||
const components = this.getRenderedComponents(); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components0.wxml`, 'components.wxml.ejs', { | ||
depth: 0, | ||
componentsDepth: 0, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender, | ||
renderComponentTemplate(compilation, inlineChildrenRender) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components0.wxml`, 'components.wxml.ejs', { | ||
depth: 0, | ||
componentsDepth: 0, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender, | ||
}); | ||
}); | ||
} | ||
async renderChildrenTemplate(compilation) { | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children0.wxml`, 'children.wxml.ejs', { | ||
depth: 0, | ||
maxDepth: Infinity, | ||
componentsDepth: 0, | ||
renderChildrenTemplate(compilation) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/children0.wxml`, 'children.wxml.ejs', { | ||
depth: 0, | ||
maxDepth: Infinity, | ||
componentsDepth: 0, | ||
}); | ||
}); | ||
} | ||
async renderWrappedComponents(compilation) { | ||
const components = this.getWhitelistedComponents(); | ||
for (const component of components) { | ||
if (component.isWrapped) { | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.wxml`, `components/${component.name}.wxml.ejs`, {}); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.json`, `components/${component.name}.json.ejs`, {}); | ||
await this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.js`, `components/${component.name}.js.ejs`, {}); | ||
renderWrappedComponents(compilation) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const components = this.getWhitelistedComponents(); | ||
for (const component of components) { | ||
if (component.isWrapped) { | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.wxml`, `components/${component.name}.wxml.ejs`, {}); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.json`, `components/${component.name}.json.ejs`, {}); | ||
yield this.renderTemplateToAsset(compilation, `${constants_1.BRIDGE_OUTPUT_PATH}/components/${component.name}.js`, `components/${component.name}.js.ejs`, {}); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
apply(compiler) { | ||
compiler.hooks.emit.tapPromise('GojiBridgeWebpackPlugin', async (compilation) => { | ||
const useFlattenBridge = this.shouldUseFlattenBridge(); | ||
if (useFlattenBridge) { | ||
compiler.hooks.emit.tapPromise('GojiBridgeWebpackPlugin', (compilation) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const useSubtree = this.shouldUseSubtree(); | ||
if (useSubtree) { | ||
// render componentX and childrenX | ||
await this.renderFlattenBridge(compilation); | ||
// render children-render component | ||
await this.renderChildrenRenderComponent(compilation); | ||
yield this.renderSubtreeBridge(compilation); | ||
// render subtree component | ||
yield this.renderChildrenRenderComponent(compilation); | ||
} | ||
@@ -136,9 +148,9 @@ else { | ||
// render component0 with inlined children0 | ||
await this.renderComponentTemplate(compilation, true); | ||
yield this.renderComponentTemplate(compilation, true); | ||
} | ||
else { | ||
// render component0 | ||
await this.renderComponentTemplate(compilation, false); | ||
yield this.renderComponentTemplate(compilation, false); | ||
// render children0 | ||
await this.renderChildrenTemplate(compilation); | ||
yield this.renderChildrenTemplate(compilation); | ||
} | ||
@@ -148,9 +160,9 @@ if (this.options.unsafe_forceChildrenRenderComponent) { | ||
// so we have to output this component even in non WeChat target | ||
await this.renderChildrenRenderComponent(compilation); | ||
yield this.renderChildrenRenderComponent(compilation); | ||
} | ||
} | ||
// render leaf-components | ||
await this.renderLeafTemplate(compilation); | ||
yield this.renderLeafTemplate(compilation); | ||
// render wrapped components | ||
await this.renderWrappedComponents(compilation); | ||
yield this.renderWrappedComponents(compilation); | ||
const pathEntries = shared_1.pathEntriesMap.get(compiler); | ||
@@ -162,9 +174,9 @@ if (!pathEntries) { | ||
// generate entry wxml | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.wxml`, 'item.wxml.ejs', { | ||
useFlattenBridge, | ||
yield this.renderTemplateToAsset(compilation, `${entrypoint}.wxml`, 'item.wxml.ejs', { | ||
useSubtree, | ||
relativePathToBridge: path_2.getRelativePathToBridge(entrypoint), | ||
}); | ||
// generate entry json | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.json`, 'item.json.ejs', { | ||
useFlattenBridge, | ||
yield this.renderTemplateToAsset(compilation, `${entrypoint}.json`, 'item.json.ejs', { | ||
useSubtree, | ||
relativePathToBridge: path_2.getRelativePathToBridge(entrypoint), | ||
@@ -175,3 +187,3 @@ components: this.getWhitelistedComponents(), | ||
} | ||
}); | ||
})); | ||
} | ||
@@ -178,0 +190,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const deepmerge_1 = __importDefault(require("deepmerge")); | ||
const json5_1 = __importDefault(require("json5")); | ||
const tslib_1 = require("tslib"); | ||
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge")); | ||
const json5_1 = tslib_1.__importDefault(require("json5")); | ||
const loadConfig_1 = require("../utils/loadConfig"); | ||
@@ -31,3 +29,3 @@ const shared_1 = require("../shared"); | ||
const { context = '' } = compiler.options; | ||
compiler.hooks.emit.tapPromise('GojiConfigWebpackPlugin', async (compilation) => { | ||
compiler.hooks.emit.tapPromise('GojiConfigWebpackPlugin', (compilation) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { target } = this.options; | ||
@@ -47,3 +45,3 @@ const pathEntries = shared_1.pathEntriesMap.get(compiler); | ||
this.updateConfigJson(compilation, appEntry, context, target); | ||
}); | ||
})); | ||
} | ||
@@ -50,0 +48,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
// @ts-ignore | ||
const SingleEntryPlugin_1 = __importDefault(require("webpack/lib/SingleEntryPlugin")); | ||
const path_1 = __importDefault(require("path")); | ||
const loader_utils_1 = __importDefault(require("loader-utils")); | ||
const replace_ext_1 = __importDefault(require("replace-ext")); | ||
const SingleEntryPlugin_1 = tslib_1.__importDefault(require("webpack/lib/SingleEntryPlugin")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const loader_utils_1 = tslib_1.__importDefault(require("loader-utils")); | ||
const replace_ext_1 = tslib_1.__importDefault(require("replace-ext")); | ||
const shared_1 = require("../shared"); | ||
@@ -12,0 +10,0 @@ const based_1 = require("./based"); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const webpack_sources_1 = require("webpack-sources"); | ||
@@ -8,0 +6,0 @@ const based_1 = require("./based"); |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const camelCase_1 = __importDefault(require("lodash/camelCase")); | ||
const kebabCase_1 = __importDefault(require("lodash/kebabCase")); | ||
const pick_1 = __importDefault(require("lodash/pick")); | ||
const tslib_1 = require("tslib"); | ||
const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase")); | ||
const kebabCase_1 = tslib_1.__importDefault(require("lodash/kebabCase")); | ||
const pick_1 = tslib_1.__importDefault(require("lodash/pick")); | ||
const components_1 = require("../constants/components"); | ||
@@ -24,8 +22,3 @@ exports.getWhitelistedComponents = (componentWhitelist) => { | ||
} | ||
simplifiedComponents.push({ | ||
...matched, | ||
events, | ||
props: pick_1.default(matched.props, properties.map(kebabCase_1.default)), | ||
simplifyId: index, | ||
}); | ||
simplifiedComponents.push(Object.assign(Object.assign({}, matched), { events, props: pick_1.default(matched.props, properties.map(kebabCase_1.default)), simplifyId: index })); | ||
} | ||
@@ -32,0 +25,0 @@ return simplifiedComponents; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = __importDefault(require("fs")); | ||
const json5_1 = __importDefault(require("json5")); | ||
const resolve_1 = __importDefault(require("resolve")); | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const json5_1 = tslib_1.__importDefault(require("json5")); | ||
const resolve_1 = tslib_1.__importDefault(require("resolve")); | ||
const loader_utils_1 = require("loader-utils"); | ||
const module_1 = __importDefault(require("module")); | ||
const module_1 = tslib_1.__importDefault(require("module")); | ||
// from https://github.com/webpack/webpack.js.org/issues/1268#issuecomment-313513988 | ||
@@ -12,0 +10,0 @@ const exec = (code, filename, context) => { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const html_minifier_1 = __importDefault(require("html-minifier")); | ||
const terser_1 = __importDefault(require("terser")); | ||
const tslib_1 = require("tslib"); | ||
const html_minifier_1 = tslib_1.__importDefault(require("html-minifier")); | ||
const terser_1 = tslib_1.__importDefault(require("terser")); | ||
const MINIMIZE_CONF = { | ||
@@ -9,0 +7,0 @@ caseSensitive: true, |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const constants_1 = require("../constants"); | ||
@@ -8,0 +6,0 @@ /** |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ejs_1 = __importDefault(require("ejs")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const view_1 = __importDefault(require("wx2swan/dist/src/view")); | ||
const api_1 = __importDefault(require("wx2swan/dist/src/api")); | ||
const api_2 = __importDefault(require("wx2swan/dist/config/wxmp2swan/api")); | ||
exports.renderTemplate = async (target, pathname, data = {}) => { | ||
const tslib_1 = require("tslib"); | ||
const ejs_1 = tslib_1.__importDefault(require("ejs")); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const view_1 = tslib_1.__importDefault(require("wx2swan/dist/src/view")); | ||
const api_1 = tslib_1.__importDefault(require("wx2swan/dist/src/api")); | ||
const api_2 = tslib_1.__importDefault(require("wx2swan/dist/config/wxmp2swan/api")); | ||
exports.renderTemplate = (target, pathname, data = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const content = fs_1.default.readFileSync(pathname).toString(); | ||
@@ -26,3 +24,3 @@ const result = ejs_1.default.render(content, data, { | ||
case 'wxml': { | ||
const { contents } = await view_1.default.transformViewContent(pathname, result, { | ||
const { contents } = yield view_1.default.transformViewContent(pathname, result, { | ||
type: 'wxmp2swan', | ||
@@ -64,3 +62,3 @@ src: '', | ||
} | ||
}; | ||
}); | ||
//# sourceMappingURL=render.js.map |
@@ -9,6 +9,3 @@ import webpack from 'webpack'; | ||
constructor(options = {}) { | ||
this.options = { | ||
...DEFAULT_OPTIONS, | ||
...options, | ||
}; | ||
this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options); | ||
} | ||
@@ -20,2 +17,3 @@ apply(compiler) { | ||
'process.env.GOJI_COMPONENT_WHITELIST': JSON.stringify(options.unstable_componentWhitelist), | ||
'process.env.GOJI_MAX_DEPTH': JSON.stringify(options.maxDepth), | ||
}).apply(compiler); | ||
@@ -22,0 +20,0 @@ new GojiBridgeWebpackPlugin(options).apply(compiler); |
@@ -12,5 +12,5 @@ import webpack from 'webpack'; | ||
private shouldInlineChildrenRender; | ||
private shouldUseFlattenBridge; | ||
private shouldUseSubtree; | ||
private useWrappedComponent; | ||
private renderFlattenBridge; | ||
private renderSubtreeBridge; | ||
private renderLeafTemplate; | ||
@@ -17,0 +17,0 @@ private renderChildrenRenderComponent; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import path from 'path'; | ||
@@ -25,17 +26,19 @@ import { unstable_SIMPLIFY_COMPONENTS as SIMPLIFY_COMPONENTS } from '@goji/core'; | ||
} | ||
async renderTemplateToAsset(compilation, assetPath, templatePath, data) { | ||
const formattedAssetPath = this.transformExtForPath(assetPath); | ||
// skip existing asset | ||
if (compilation.assets[formattedAssetPath] !== undefined) { | ||
console.warn('skip existing asset', formattedAssetPath); | ||
return; | ||
} | ||
let content = await this.renderTemplate(templatePath, data); | ||
if (this.options.minimize) { | ||
content = minimize(content, path.extname(assetPath)); | ||
} | ||
compilation.assets[formattedAssetPath] = { | ||
source: () => content, | ||
size: () => content.length, | ||
}; | ||
renderTemplateToAsset(compilation, assetPath, templatePath, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const formattedAssetPath = this.transformExtForPath(assetPath); | ||
// skip existing asset | ||
if (compilation.assets[formattedAssetPath] !== undefined) { | ||
console.warn('skip existing asset', formattedAssetPath); | ||
return; | ||
} | ||
let content = yield this.renderTemplate(templatePath, data); | ||
if (this.options.minimize) { | ||
content = minimize(content, path.extname(assetPath)); | ||
} | ||
compilation.assets[formattedAssetPath] = { | ||
source: () => content, | ||
size: () => content.length, | ||
}; | ||
}); | ||
} | ||
@@ -49,3 +52,3 @@ shouldInlineChildrenRender() { | ||
} | ||
shouldUseFlattenBridge() { | ||
shouldUseSubtree() { | ||
const { target } = this.options; | ||
@@ -58,70 +61,82 @@ return target === 'wechat' || target === 'qq'; | ||
} | ||
async renderFlattenBridge(compilation) { | ||
const components = this.getRenderedComponents(); | ||
const { maxDepth } = this.options; | ||
for (let depth = 0; depth < maxDepth; depth += 1) { | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children${depth}.wxml`, 'children.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
renderSubtreeBridge(compilation) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
const { maxDepth } = this.options; | ||
for (let depth = 0; depth < maxDepth; depth += 1) { | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children${depth}.wxml`, 'children.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
}); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components${depth}.wxml`, 'components.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender: this.shouldInlineChildrenRender(), | ||
}); | ||
} | ||
}); | ||
} | ||
renderLeafTemplate(compilation) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/leaf-components.wxml`, `leaf-components.wxml.ejs`, { | ||
components: components.filter(c => c.isLeaf), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components${depth}.wxml`, 'components.wxml.ejs', { | ||
depth, | ||
maxDepth, | ||
componentsDepth: depth + 1, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender: this.shouldInlineChildrenRender(), | ||
}); | ||
} | ||
} | ||
async renderLeafTemplate(compilation) { | ||
const components = this.getRenderedComponents(); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/leaf-components.wxml`, `leaf-components.wxml.ejs`, { | ||
components: components.filter(c => c.isLeaf), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
} | ||
async renderChildrenRenderComponent(compilation) { | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children-render.js`, 'children-render.js.ejs', {}); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children-render.json`, 'children-render.json.ejs', { | ||
relativePathToBridge: '.', | ||
components: this.getWhitelistedComponents(), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
renderChildrenRenderComponent(compilation) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/subtree.js`, 'subtree.js.ejs', {}); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/subtree.json`, 'subtree.json.ejs', { | ||
relativePathToBridge: '.', | ||
components: this.getWhitelistedComponents(), | ||
useWrappedComponent: this.useWrappedComponent(), | ||
}); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/subtree.wxml`, 'subtree.wxml.ejs', {}); | ||
}); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children-render.wxml`, 'children-render.wxml.ejs', {}); | ||
} | ||
async renderComponentTemplate(compilation, inlineChildrenRender) { | ||
const components = this.getRenderedComponents(); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components0.wxml`, 'components.wxml.ejs', { | ||
depth: 0, | ||
componentsDepth: 0, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender, | ||
renderComponentTemplate(compilation, inlineChildrenRender) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const components = this.getRenderedComponents(); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components0.wxml`, 'components.wxml.ejs', { | ||
depth: 0, | ||
componentsDepth: 0, | ||
components: components.filter(c => !c.isLeaf), | ||
inlineChildrenRender, | ||
}); | ||
}); | ||
} | ||
async renderChildrenTemplate(compilation) { | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children0.wxml`, 'children.wxml.ejs', { | ||
depth: 0, | ||
maxDepth: Infinity, | ||
componentsDepth: 0, | ||
renderChildrenTemplate(compilation) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/children0.wxml`, 'children.wxml.ejs', { | ||
depth: 0, | ||
maxDepth: Infinity, | ||
componentsDepth: 0, | ||
}); | ||
}); | ||
} | ||
async renderWrappedComponents(compilation) { | ||
const components = this.getWhitelistedComponents(); | ||
for (const component of components) { | ||
if (component.isWrapped) { | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.wxml`, `components/${component.name}.wxml.ejs`, {}); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.json`, `components/${component.name}.json.ejs`, {}); | ||
await this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.js`, `components/${component.name}.js.ejs`, {}); | ||
renderWrappedComponents(compilation) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const components = this.getWhitelistedComponents(); | ||
for (const component of components) { | ||
if (component.isWrapped) { | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.wxml`, `components/${component.name}.wxml.ejs`, {}); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.json`, `components/${component.name}.json.ejs`, {}); | ||
yield this.renderTemplateToAsset(compilation, `${BRIDGE_OUTPUT_PATH}/components/${component.name}.js`, `components/${component.name}.js.ejs`, {}); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
apply(compiler) { | ||
compiler.hooks.emit.tapPromise('GojiBridgeWebpackPlugin', async (compilation) => { | ||
const useFlattenBridge = this.shouldUseFlattenBridge(); | ||
if (useFlattenBridge) { | ||
compiler.hooks.emit.tapPromise('GojiBridgeWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () { | ||
const useSubtree = this.shouldUseSubtree(); | ||
if (useSubtree) { | ||
// render componentX and childrenX | ||
await this.renderFlattenBridge(compilation); | ||
// render children-render component | ||
await this.renderChildrenRenderComponent(compilation); | ||
yield this.renderSubtreeBridge(compilation); | ||
// render subtree component | ||
yield this.renderChildrenRenderComponent(compilation); | ||
} | ||
@@ -131,9 +146,9 @@ else { | ||
// render component0 with inlined children0 | ||
await this.renderComponentTemplate(compilation, true); | ||
yield this.renderComponentTemplate(compilation, true); | ||
} | ||
else { | ||
// render component0 | ||
await this.renderComponentTemplate(compilation, false); | ||
yield this.renderComponentTemplate(compilation, false); | ||
// render children0 | ||
await this.renderChildrenTemplate(compilation); | ||
yield this.renderChildrenTemplate(compilation); | ||
} | ||
@@ -143,9 +158,9 @@ if (this.options.unsafe_forceChildrenRenderComponent) { | ||
// so we have to output this component even in non WeChat target | ||
await this.renderChildrenRenderComponent(compilation); | ||
yield this.renderChildrenRenderComponent(compilation); | ||
} | ||
} | ||
// render leaf-components | ||
await this.renderLeafTemplate(compilation); | ||
yield this.renderLeafTemplate(compilation); | ||
// render wrapped components | ||
await this.renderWrappedComponents(compilation); | ||
yield this.renderWrappedComponents(compilation); | ||
const pathEntries = pathEntriesMap.get(compiler); | ||
@@ -157,9 +172,9 @@ if (!pathEntries) { | ||
// generate entry wxml | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.wxml`, 'item.wxml.ejs', { | ||
useFlattenBridge, | ||
yield this.renderTemplateToAsset(compilation, `${entrypoint}.wxml`, 'item.wxml.ejs', { | ||
useSubtree, | ||
relativePathToBridge: getRelativePathToBridge(entrypoint), | ||
}); | ||
// generate entry json | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.json`, 'item.json.ejs', { | ||
useFlattenBridge, | ||
yield this.renderTemplateToAsset(compilation, `${entrypoint}.json`, 'item.json.ejs', { | ||
useSubtree, | ||
relativePathToBridge: getRelativePathToBridge(entrypoint), | ||
@@ -170,5 +185,5 @@ components: this.getWhitelistedComponents(), | ||
} | ||
}); | ||
})); | ||
} | ||
} | ||
//# sourceMappingURL=bridge.js.map |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import merge from 'deepmerge'; | ||
@@ -26,3 +27,3 @@ import JSON5 from 'json5'; | ||
const { context = '' } = compiler.options; | ||
compiler.hooks.emit.tapPromise('GojiConfigWebpackPlugin', async (compilation) => { | ||
compiler.hooks.emit.tapPromise('GojiConfigWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () { | ||
const { target } = this.options; | ||
@@ -42,5 +43,5 @@ const pathEntries = pathEntriesMap.get(compiler); | ||
this.updateConfigJson(compilation, appEntry, context, target); | ||
}); | ||
})); | ||
} | ||
} | ||
//# sourceMappingURL=config.js.map |
@@ -19,8 +19,3 @@ import camelCase from 'lodash/camelCase'; | ||
} | ||
simplifiedComponents.push({ | ||
...matched, | ||
events, | ||
props: pick(matched.props, properties.map(kebabCase)), | ||
simplifyId: index, | ||
}); | ||
simplifiedComponents.push(Object.assign(Object.assign({}, matched), { events, props: pick(matched.props, properties.map(kebabCase)), simplifyId: index })); | ||
} | ||
@@ -27,0 +22,0 @@ return simplifiedComponents; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import ejs from 'ejs'; | ||
@@ -7,3 +8,3 @@ import fs from 'fs'; | ||
import wx2swanConfigApi from 'wx2swan/dist/config/wxmp2swan/api'; | ||
export const renderTemplate = async (target, pathname, data = {}) => { | ||
export const renderTemplate = (target, pathname, data = {}) => __awaiter(void 0, void 0, void 0, function* () { | ||
const content = fs.readFileSync(pathname).toString(); | ||
@@ -22,3 +23,3 @@ const result = ejs.render(content, data, { | ||
case 'wxml': { | ||
const { contents } = await wx2swanView.transformViewContent(pathname, result, { | ||
const { contents } = yield wx2swanView.transformViewContent(pathname, result, { | ||
type: 'wxmp2swan', | ||
@@ -60,3 +61,3 @@ src: '', | ||
} | ||
}; | ||
}); | ||
//# sourceMappingURL=render.js.map |
{ | ||
"name": "@goji/webpack-plugin", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "Goji Webpack Plugin", | ||
@@ -36,3 +36,5 @@ "main": "dist/cjs/cjs.js", | ||
"devDependencies": { | ||
"@goji/core": "^0.5.3", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4", | ||
"@babel/plugin-proposal-optional-chaining": "^7.7.4", | ||
"@goji/core": "^0.5.4", | ||
"@types/ejs": "^2.6.3", | ||
@@ -82,3 +84,3 @@ "@types/html-minifier": "^3.5.3", | ||
}, | ||
"gitHead": "8eb70c25a54c41cfe2502c4a218359c48e82af69" | ||
"gitHead": "41e933b6e4efc40ba177c3349dab49871cc2e27d" | ||
} |
@@ -24,2 +24,3 @@ import webpack from 'webpack'; | ||
'process.env.GOJI_COMPONENT_WHITELIST': JSON.stringify(options.unstable_componentWhitelist), | ||
'process.env.GOJI_MAX_DEPTH': JSON.stringify(options.maxDepth), | ||
}).apply(compiler); | ||
@@ -26,0 +27,0 @@ new GojiBridgeWebpackPlugin(options).apply(compiler); |
@@ -64,3 +64,3 @@ import webpack from 'webpack'; | ||
private shouldUseFlattenBridge() { | ||
private shouldUseSubtree() { | ||
const { target } = this.options; | ||
@@ -75,3 +75,3 @@ return target === 'wechat' || target === 'qq'; | ||
private async renderFlattenBridge(compilation: webpack.compilation.Compilation) { | ||
private async renderSubtreeBridge(compilation: webpack.compilation.Compilation) { | ||
const components = this.getRenderedComponents(); | ||
@@ -121,4 +121,4 @@ const { maxDepth } = this.options; | ||
compilation, | ||
`${BRIDGE_OUTPUT_PATH}/children-render.js`, | ||
'children-render.js.ejs', | ||
`${BRIDGE_OUTPUT_PATH}/subtree.js`, | ||
'subtree.js.ejs', | ||
{}, | ||
@@ -128,4 +128,4 @@ ); | ||
compilation, | ||
`${BRIDGE_OUTPUT_PATH}/children-render.json`, | ||
'children-render.json.ejs', | ||
`${BRIDGE_OUTPUT_PATH}/subtree.json`, | ||
'subtree.json.ejs', | ||
{ | ||
@@ -139,4 +139,4 @@ relativePathToBridge: '.', | ||
compilation, | ||
`${BRIDGE_OUTPUT_PATH}/children-render.wxml`, | ||
'children-render.wxml.ejs', | ||
`${BRIDGE_OUTPUT_PATH}/subtree.wxml`, | ||
'subtree.wxml.ejs', | ||
{}, | ||
@@ -205,8 +205,8 @@ ); | ||
compiler.hooks.emit.tapPromise('GojiBridgeWebpackPlugin', async compilation => { | ||
const useFlattenBridge = this.shouldUseFlattenBridge(); | ||
const useSubtree = this.shouldUseSubtree(); | ||
if (useFlattenBridge) { | ||
if (useSubtree) { | ||
// render componentX and childrenX | ||
await this.renderFlattenBridge(compilation); | ||
// render children-render component | ||
await this.renderSubtreeBridge(compilation); | ||
// render subtree component | ||
await this.renderChildrenRenderComponent(compilation); | ||
@@ -241,3 +241,3 @@ } else { | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.wxml`, 'item.wxml.ejs', { | ||
useFlattenBridge, | ||
useSubtree, | ||
relativePathToBridge: getRelativePathToBridge(entrypoint), | ||
@@ -247,3 +247,3 @@ }); | ||
await this.renderTemplateToAsset(compilation, `${entrypoint}.json`, 'item.json.ejs', { | ||
useFlattenBridge, | ||
useSubtree, | ||
relativePathToBridge: getRelativePathToBridge(entrypoint), | ||
@@ -250,0 +250,0 @@ components: this.getWhitelistedComponents(), |
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"target": "es6", | ||
"declaration": true, | ||
@@ -13,2 +13,3 @@ "module": "esnext", | ||
"skipLibCheck": true, | ||
"importHelpers": true, | ||
"moduleResolution": "node", | ||
@@ -15,0 +16,0 @@ "jsx": "react" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
326348
0.28%18
12.5%7096
-0.07%