Skip to content

Добавит обработку globals из bundle.config #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ module.exports = {
// Обычно это ./dist/<extension_name>.bundle.js
// Необходимо указать относительный путь
output: string || {js: string, css: string},


// Алиасы для внешних импортов
// https://rollupjs.org/configuration-options/#output-globals
globals: { [id: string]: string }

// Неймспейс, в который будут добавлены все экспорты из файла указанного в input
// Например 'BX.Main.Filter'
namespace: string,
Expand Down
1 change: 1 addition & 0 deletions src/@types/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface BundleConfig {
js: string,
css: string,
},
globals: {[key: string]: string},
name: string,
treeshake: boolean,
adjustConfigPhp: boolean,
Expand Down
1 change: 1 addition & 0 deletions src/utils/get-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default function getConfigs(directory: string): BundleConfig {
acc.push({
input: path.resolve(context, currentConfig.input),
output,
globals: currentConfig.globals || {},
name: currentConfig.namespace || '',
treeshake: currentConfig.treeshake !== false,
adjustConfigPhp: currentConfig.adjustConfigPhp !== false,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/get-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import fs from 'fs';
import type BundleConfig from '../@types/config';

export default function getGlobals(imports: string[], {context}: BundleConfig): {[key: string]: string} {
export default function getGlobals(imports: string[], {context, globals}: BundleConfig): {[key: string]: string} {
return imports.reduce((accumulator, extensionName) => {
const parsedExtensionName = extensionName.split('.');
const moduleName = parsedExtensionName.shift();
Expand Down Expand Up @@ -44,6 +44,8 @@ export default function getGlobals(imports: string[], {context}: BundleConfig):
if (config.namespace && config.namespace.length) {
moduleAlias = config.namespace;
}
} else if (globals.hasOwnProperty(moduleName)) {
moduleAlias = globals[moduleName];
}

accumulator[extensionName] = moduleAlias;
Expand Down