From d2acd5cef9e3e6bb76e68208523196dfaf97d39c Mon Sep 17 00:00:00 2001 From: Steel Brain Date: Sat, 1 Sep 2018 11:58:34 -0700 Subject: [PATCH] wip --- .../src/index.js | 4 --- .../.npmignore | 2 ++ .../package.json | 22 +++++++++++++++ .../src/index.js | 17 +++++++++++ packages/pundle-preset-default/package.json | 1 + packages/pundle-preset-default/src/index.js | 28 +++++++++++++------ 6 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 packages/pundle-job-transformer-js-dedupe/.npmignore create mode 100644 packages/pundle-job-transformer-js-dedupe/package.json create mode 100644 packages/pundle-job-transformer-js-dedupe/src/index.js diff --git a/packages/pundle-job-transformer-js-common/src/index.js b/packages/pundle-job-transformer-js-common/src/index.js index 70bb6418..7c4e10d9 100644 --- a/packages/pundle-job-transformer-js-common/src/index.js +++ b/packages/pundle-job-transformer-js-common/src/index.js @@ -21,10 +21,6 @@ function createComponent({ name = '_common_' }: { name?: string } = {}) { name: manifest.name, version: manifest.version, async callback({ context, job }) { - if (context.config.target === 'node') { - return null - } - const chunkToFiles = new Map() job.chunks.forEach(chunk => { diff --git a/packages/pundle-job-transformer-js-dedupe/.npmignore b/packages/pundle-job-transformer-js-dedupe/.npmignore new file mode 100644 index 00000000..644cac74 --- /dev/null +++ b/packages/pundle-job-transformer-js-dedupe/.npmignore @@ -0,0 +1,2 @@ +src/ +*.flow diff --git a/packages/pundle-job-transformer-js-dedupe/package.json b/packages/pundle-job-transformer-js-dedupe/package.json new file mode 100644 index 00000000..92226398 --- /dev/null +++ b/packages/pundle-job-transformer-js-dedupe/package.json @@ -0,0 +1,22 @@ +{ + "name": "pundle-job-transformer-js-dedupe", + "version": "3.0.0-beta8", + "description": "TODO", + "repository": { + "type": "git", + "url": "git+https://github.com/steelbrain/pundle.git" + }, + "main": "lib/index.js", + "flow:main": "src/index.js", + "scripts": {}, + "dependencies": { + }, + "peerDependencies": { + "pundle-api": "3.0.0-beta8" + }, + "author": "steelbrain", + "license": "MIT", + "devDependencies": { + "pundle-api": "^3.0.0-beta8" + } +} diff --git a/packages/pundle-job-transformer-js-dedupe/src/index.js b/packages/pundle-job-transformer-js-dedupe/src/index.js new file mode 100644 index 00000000..c32731bb --- /dev/null +++ b/packages/pundle-job-transformer-js-dedupe/src/index.js @@ -0,0 +1,17 @@ +// @flow + +import { createJobTransformer } from 'pundle-api' +import { name, version } from '../package.json' + +function createComponent() { + return createJobTransformer({ + name, + version, + callback({ context, worker, job }) { + console.log('dedupe transformer') + return null + }, + }) +} + +module.exports = createComponent diff --git a/packages/pundle-preset-default/package.json b/packages/pundle-preset-default/package.json index ac70b0c2..4d69103b 100644 --- a/packages/pundle-preset-default/package.json +++ b/packages/pundle-preset-default/package.json @@ -18,6 +18,7 @@ "pundle-chunk-transformer-cssnano": "^3.0.0-beta9", "pundle-chunk-transformer-uglify": "^3.0.0-beta9", "pundle-job-transformer-js-common": "^3.0.0-beta9", + "pundle-job-transformer-js-dedupe": "^3.0.0-beta9", "pundle-reporter-cli": "^3.0.0-beta9", "pundle-resolver-default": "^3.0.0-beta9", "pundle-transformer-babel": "^3.0.0-beta9", diff --git a/packages/pundle-preset-default/src/index.js b/packages/pundle-preset-default/src/index.js index 5c4287c6..5742d489 100644 --- a/packages/pundle-preset-default/src/index.js +++ b/packages/pundle-preset-default/src/index.js @@ -71,7 +71,7 @@ function getPresetComponents({ html?: boolean, }, optimize?: { - js?: boolean | { uglify?: boolean | Object }, + js?: boolean | { uglify?: boolean | Object, common?: boolean | Object, dedupe?: boolean | Object }, css?: boolean | { cssnano?: boolean | Object }, html?: boolean, }, @@ -258,14 +258,26 @@ function getPresetComponents({ components.push(require('pundle-chunk-generator-html')()) } components.push(require('pundle-chunk-generator-static')()) + if (optimizeJS) { - components.push(require('pundle-job-transformer-js-common')()) - components.push( - require('pundle-chunk-transformer-uglify')({ - uglifier: 'terser', - ...(optimizeJS && optimizeJS.uglify), - }), - ) + if (typeof optimizeJS === 'boolean' || optimizeJS.common) { + components.push(require('pundle-job-transformer-js-common')()) + } + if (typeof optimizeJS === 'boolean' || optimizeJS.uglify) { + components.push( + require('pundle-chunk-transformer-uglify')({ + uglifier: 'terser', + ...(optimizeJS && optimizeJS.uglify), + }), + ) + } + if (typeof optimizeJS === 'boolean' || optimizeJS.dedupe) { + components.push( + require('pundle-job-transformer-js-dedupe')({ + ...(optimizeJS && optimizeJS.dedupe), + }), + ) + } } if (optimizeCSS) { components.push(