Skip to content

Commit

Permalink
Tweak library extraction logic
Browse files Browse the repository at this point in the history
This works better with pnpm
  • Loading branch information
thecrypticace committed Nov 8, 2021
1 parent 1214565 commit 8541e79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/components/Extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,20 @@ class Extract {
);
}

return new RegExp(`${pattern}(${extra})`, 'i');
const regex = new RegExp(`${pattern}(${extra})`, 'i');

return mod => {
const request = mod.rawRequest;

if (Array.isArray(libraries) && libraries.includes(request)) {
return true;
}

const name = mod.nameForCondition();

// TODO: This causes the vendor backend+frontend test to fail
return name && regex.test(name);
};
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/features/extraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('JS compilation with vendor extraction config', async t => {
assert.fileExists(`test/fixtures/app/dist/js/app.js`, t);

// We extracted vue to the library file
assert.fileContains(`test/fixtures/app/dist/js/libraries.js`, 'vue2', t);
assert.fileContains(`test/fixtures/app/dist/js/libraries.js`, 'Vue.js v2', t);

// But not core-js
assert.fileContains(`test/fixtures/app/dist/js/app.js`, 'core-js', t);
Expand All @@ -37,15 +37,15 @@ test('vendor extraction with no requested JS compilation will throw an error', a
test('JS compilation with vendor extraction with default config', async t => {
mix.js(`test/fixtures/app/src/extract/app.js`, 'js')
.vue({ version: 2 })
.extract(['vue2']);
.extract(['vue2', 'vue@2.6.14']);

await webpack.compile();

assert.fileExists(`test/fixtures/app/dist/js/manifest.js`, t);
assert.fileExists(`test/fixtures/app/dist/js/vendor.js`, t);
assert.fileExists(`test/fixtures/app/dist/js/app.js`, t);

assert.fileContains(`test/fixtures/app/dist/js/vendor.js`, 'vue2', t);
assert.fileContains(`test/fixtures/app/dist/js/vendor.js`, 'Vue.js v2', t);
});

test('JS compilation with total vendor extraction', async t => {
Expand All @@ -57,7 +57,7 @@ test('JS compilation with total vendor extraction', async t => {
assert.fileExists(`test/fixtures/app/dist/js/vendor.js`, t);
assert.fileExists(`test/fixtures/app/dist/js/app.js`, t);

assert.fileContains(`test/fixtures/app/dist/js/vendor.js`, 'vue2', t);
assert.fileContains(`test/fixtures/app/dist/js/vendor.js`, 'Vue.js v2', t);
assert.fileContains(`test/fixtures/app/dist/js/vendor.js`, 'core-js', t);

let fs = require('fs-extra');
Expand Down

0 comments on commit 8541e79

Please sign in to comment.