Skip to content

Commit

Permalink
Use basename on rawRequest for generating output directory
Browse files Browse the repository at this point in the history
directory of resolved request is not sufficient because the resolved file of WordPress dependencies is within the `build-module` directory and would output as such. Instead format in such a way that we can call basename on the _raw_ requested path (e.g. `./editor` -> "editor", `./node_modules/@wordpress/hooks" -> "hooks")
  • Loading branch information
aduth committed Feb 9, 2018
1 parent 29b84ba commit 938a7c1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const webpack = require( 'webpack' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
const { reduce, escapeRegExp, castArray, get } = require( 'lodash' );
const { basename, dirname } = require( 'path' );
const { basename } = require( 'path' );

// Main CSS loader for everything but blocks..
const mainCSSExtractTextPlugin = new ExtractTextPlugin( {
filename: './[dir]/build/style.css',
filename: './[basename]/build/style.css',
} );

// CSS loader for styles specific to block editing.
Expand Down Expand Up @@ -130,7 +130,7 @@ const config = {
entryPointNames.reduce( ( memo, entryPoint ) => {
entryPoint = castArray( entryPoint );
const [ name, path = name ] = entryPoint;
memo[ name ] = `./${ path }/index.js`;
memo[ name ] = `./${ path }`;
return memo;
}, {} ),
packageNames.reduce( ( memo, packageName ) => {
Expand All @@ -139,7 +139,7 @@ const config = {
}, {} )
),
output: {
filename: '[dir]/build/index.js',
filename: '[basename]/build/index.js',
path: __dirname,
library: [ 'wp', '[name]' ],
libraryTarget: 'this',
Expand Down Expand Up @@ -202,10 +202,10 @@ const config = {
debug: process.env.NODE_ENV !== 'production',
} ),
new CustomTemplatedPathPlugin( {
dir( path, data ) {
const request = get( data, [ 'chunk', 'entryModule', 'request' ] );
if ( request ) {
return basename( dirname( request ) );
basename( path, data ) {
const rawRequest = get( data, [ 'chunk', 'entryModule', 'rawRequest' ] );
if ( rawRequest ) {
return basename( rawRequest );
}

return path;
Expand Down

0 comments on commit 938a7c1

Please sign in to comment.