Skip to content

Conflict with externals #42

@kucrut

Description

@kucrut

The way externals are currently defined makes it impossible for to export own's library to the global this.

Example config:

module.exports = {
	// ...
	name: 'myPlugin',
	entry: {
		components: filePath( 'assets/src/components/index.js' ),
		dashboard: filePath( 'assets/src/dashboard.js' ),
		preview: filePath( 'assets/src/preview.js' ),
	},
	output: {
		library: [ 'myPlugin', '[name]' ],
		libraryTarget: 'this',
		path: filePath( '/assets/dist/' ),
	},
	resolve: {
		alias: {
			'@myPlugin/components': filePath( '/assets/src/components/' ),
		},
	},
};

The intention was to make the entrypoints available under this.myPlugin object. However, since webpack helpers defined the externals differently, they're overriden by this config.

From webpack docs:

Note that not setting a output.library will cause all properties returned by the entry point to be assigned to the given object; there are no checks against existing property names.

One possible solution is to update externals definition to:

[ `@wordpress/${ name }` ]: { this: [ 'wp', camelCaseDash( name ) ] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions