Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm install @wpsyntex/polylang-build-scripts
Install the peer dependencies in the consumer project (versions below are the minimum supported):

```bash
npm install -D clean-webpack-plugin copy-webpack-plugin css-loader css-minimizer-webpack-plugin glob mini-css-extract-plugin terser-webpack-plugin webpack webpack-cli
npm install -D clean-webpack-plugin css-loader css-minimizer-webpack-plugin glob mini-css-extract-plugin terser-webpack-plugin webpack webpack-cli
```

Add `sass` and `sass-loader` when using `getReactifiedConfig` with `sassLoadPaths`.
Expand Down
5 changes: 4 additions & 1 deletion configs/vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const getVanillaConfig = ( {
...jsFileNames.map( transformJsEntry( jsBuildDirectory, false ) ),
...jsFileNames.map( transformJsEntry( jsBuildDirectory, true ) ),
...cssFileNames.map(
transformCssEntry( cssBuildDirectory, isProduction )
transformCssEntry( cssBuildDirectory, false, isProduction )
),
...cssFileNames.map(
transformCssEntry( cssBuildDirectory, true, isProduction )
),
];
};
Expand Down
50 changes: 36 additions & 14 deletions configs/vanilla.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ jest.mock( '../main', () => {
},
} );
} ),
transformCssEntry: jest.fn( ( destination, isProduction ) => {
transformCssEntry: jest.fn( ( destination, minimize, isProduction ) => {
return ( filename ) => ( {
entry: { [ mockPath.parse( filename ).name ]: filename },
output: {
filename: '[name].work',
path: destination,
},
devtool: ! isProduction ? 'source-map' : false,
optimization: {
minimize,
},
devtool: ! minimize && ! isProduction ? 'source-map' : false,
} );
} ),
};
Expand Down Expand Up @@ -209,7 +212,7 @@ describe( 'getVanillaConfig', () => {
expect( unminifiedJsConfigs ).toHaveLength( 2 );
} );

it( 'should create CSS configs with proper settings', () => {
it( 'should create both minified and unminified configs for CSS files', () => {
glob.sync.mockImplementation( ( pattern ) => {
if ( pattern === '**/*.css' ) {
return [ 'admin/style.css', 'frontend/style.css' ];
Expand All @@ -228,9 +231,18 @@ describe( 'getVanillaConfig', () => {
const cssConfigs = configs.filter(
( config ) => config.output.filename === '[name].work'
);
expect( cssConfigs ).toHaveLength( 2 );
expect( cssConfigs ).toHaveLength( 4 );

const unminifiedCssConfigs = cssConfigs.filter(
( config ) => config.optimization.minimize === false
);
const minifiedCssConfigs = cssConfigs.filter(
( config ) => config.optimization.minimize === true
);

expect( unminifiedCssConfigs ).toHaveLength( 2 );
expect( minifiedCssConfigs ).toHaveLength( 2 );

// Check CSS configs have correct output path
cssConfigs.forEach( ( config ) => {
expect( config.output.path ).toBe( cssBuildDirectory );
} );
Expand Down Expand Up @@ -307,10 +319,10 @@ describe( 'getVanillaConfig', () => {
const cssConfigs = configs.filter(
( config ) => config.output.filename === '[name].work'
);
expect( cssConfigs ).toHaveLength( 2 );
expect( cssConfigs ).toHaveLength( 4 );
} );

it( 'should pass isProduction flag to CSS transformer', () => {
it( 'should pass isProduction flag to unminified CSS transformer', () => {
glob.sync.mockImplementation( ( pattern ) => {
if ( pattern === '**/*.css' ) {
return [ 'style.css' ];
Expand All @@ -333,16 +345,26 @@ describe( 'getVanillaConfig', () => {
isProduction: false,
} );

// Check devtool setting (source maps enabled in dev mode)
const prodCssConfig = prodConfig.find(
( config ) => config.output.filename === '[name].work'
// Check devtool setting (source maps enabled in dev mode for unminified CSS only)
const prodUnminifiedCssConfig = prodConfig.find(
( config ) =>
config.output.filename === '[name].work' &&
config.optimization.minimize === false
);
const devCssConfig = devConfig.find(
( config ) => config.output.filename === '[name].work'
const devUnminifiedCssConfig = devConfig.find(
( config ) =>
config.output.filename === '[name].work' &&
config.optimization.minimize === false
);
const devMinifiedCssConfig = devConfig.find(
( config ) =>
config.output.filename === '[name].work' &&
config.optimization.minimize === true
);

expect( prodCssConfig.devtool ).toBe( false );
expect( devCssConfig.devtool ).toBe( 'source-map' );
expect( prodUnminifiedCssConfig.devtool ).toBe( false );
expect( devUnminifiedCssConfig.devtool ).toBe( 'source-map' );
expect( devMinifiedCssConfig.devtool ).toBe( false );
} );

it( 'should use correct build directories', () => {
Expand Down
Loading
Loading