From ef322f8fa1725f56b89d91bf4b1bdbb8182248f4 Mon Sep 17 00:00:00 2001 From: Maxim Kosterin Date: Wed, 5 Jan 2022 21:10:24 +0300 Subject: [PATCH] Add include and exclude options and update packages (#93) --- README.md | 6 ++- package-lock.json | 121 +++++++++++++++++++++++++++++++++++++--------- package.json | 9 ++-- src/plugin.js | 45 +++++++++-------- 4 files changed, 133 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 657297c..17bdfb4 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,11 @@ const build = async () => { const bundle = await rollup({ input: "src/index.js", external: ["vue", "vuetify/lib"], - plugins: [postcss(), vue(), vuetify()], + plugins: [ + postcss(), + vue(), + vuetify({ include: 'src/**', exclude: 'someFolder/**' }/* options are optional */) + ], }); bundle.write({ diff --git a/package-lock.json b/package-lock.json index 777ffcc..9e53c52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -500,6 +500,11 @@ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, + "@types/json-schema": { + "version": "7.0.9", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", + "integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==" + }, "@types/node": { "version": "14.11.8", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.8.tgz", @@ -603,6 +608,11 @@ "uri-js": "^4.2.2" } }, + "ajv-keywords": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==" + }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -992,6 +1002,11 @@ "caller-callsite": "^2.0.0" } }, + "callsite": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", + "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=" + }, "callsites": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", @@ -1645,6 +1660,14 @@ "ms": "^2.1.1" } }, + "decache": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/decache/-/decache-4.6.1.tgz", + "integrity": "sha512-ohApBM8u9ygepJCjgBrEZSSxPjc0T/PJkD+uNyxXPkqudyUpdXpwJYp0VISm2WrPVzASU6DZyIi6BWdyw7uJ2Q==", + "requires": { + "callsite": "^1.0.0" + } + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -2028,16 +2051,12 @@ "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, - "optional": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true, - "optional": true + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" }, "fastparse": { "version": "1.1.2", @@ -2045,6 +2064,27 @@ "integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==", "dev": true }, + "file-loader": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-6.2.0.tgz", + "integrity": "sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==", + "requires": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + }, + "dependencies": { + "loader-utils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz", + "integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==", + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + } + } + } + }, "fill-range": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", @@ -2778,9 +2818,7 @@ "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "optional": true + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, "json-stringify-safe": { "version": "5.0.1", @@ -2874,6 +2912,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "dev": true, "requires": { "big.js": "^5.2.2", "emojis-list": "^3.0.0", @@ -2884,6 +2923,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, "requires": { "minimist": "^1.2.0" } @@ -4358,9 +4398,7 @@ "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "dev": true, - "optional": true + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "q": { "version": "1.5.1", @@ -4831,6 +4869,29 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "dev": true }, + "schema-utils": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz", + "integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==", + "requires": { + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" + }, + "dependencies": { + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + } + } + }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -5461,8 +5522,6 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", - "dev": true, - "optional": true, "requires": { "punycode": "^2.1.0" } @@ -5522,9 +5581,9 @@ "optional": true }, "vue": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.12.tgz", - "integrity": "sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg==", + "version": "2.6.14", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.14.tgz", + "integrity": "sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ==", "dev": true }, "vue-class-component": { @@ -5572,17 +5631,31 @@ "dev": true }, "vuetify": { - "version": "2.3.14", - "resolved": "https://registry.npmjs.org/vuetify/-/vuetify-2.3.14.tgz", - "integrity": "sha512-1Ys1MreJQOL/Ddp3YotBi1SlC2+1A0/RVkDXX3Azspt8incPdAnNB0JyChHiJ/TM+L+KSA7T4EXF9YDrCWENmg==", + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/vuetify/-/vuetify-2.6.1.tgz", + "integrity": "sha512-WtqarqEIJlhiwl1TShtkq58xtfbHpn4BjkuQtsL7mAs2eHCo7QjA3tUm7Dx/NmDc4wa2ghUUth36jTdG+CCWRg==", "dev": true }, "vuetify-loader": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/vuetify-loader/-/vuetify-loader-1.4.3.tgz", - "integrity": "sha512-fS0wRil682Ebsj2as+eruBoMPKaQYDhu/fDAndnTItzSY4RK4LOEIsssVL4vD6QY8dvUgoGL84SUQ6vGr777CA==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/vuetify-loader/-/vuetify-loader-1.7.3.tgz", + "integrity": "sha512-1Kt6Rfvuw3i9BBlxC9WTMnU3WEU7IBWQmDX+fYGAVGpzWCX7oHythUIwPCZGShHSYcPMKSDbXTPP8UvT5RNw8Q==", "requires": { - "loader-utils": "^1.2.0" + "decache": "^4.6.0", + "file-loader": "^6.2.0", + "loader-utils": "^2.0.0" + }, + "dependencies": { + "loader-utils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz", + "integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==", + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + } + } } }, "window-size": { diff --git a/package.json b/package.json index 9a037df..f125d3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-vuetify", - "version": "0.2.4", + "version": "0.2.5", "description": "A-la-carte (treeshaking) for you vuetify", "main": "src/plugin.js", "scripts": { @@ -33,19 +33,20 @@ "@rollup/plugin-node-resolve": "9.0.0", "@rollup/plugin-replace": "2.3.3", "@rollup/plugin-typescript": "3.1.1", + "rollup-pluginutils": "^2.8.2", "rollup": "2.32.0", "rollup-plugin-postcss": "3.1.8", "rollup-plugin-typescript2": "0.28.0", "rollup-plugin-vue": "5.1.9", "typescript": "4.0.3", - "vue": "2.6.12", + "vue": "2.6.14", "vue-template-compiler": "2.6.12", "vue-class-decorator": "7.6.3", "vue-property-decorator": "9.0.2", - "vuetify": "2.3.14" + "vuetify": "^2.4.4" }, "dependencies": { "jscodeshift": "^0.11.0", - "vuetify-loader": "^1.4.3" + "vuetify-loader": "^1.7.2" } } diff --git a/src/plugin.js b/src/plugin.js index 366a0e5..2e5f9cf 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -1,3 +1,4 @@ +const { createFilter } = require("rollup-pluginutils"); const load = require("./load"); const extract = require("./extract"); const transform = require("./transform"); @@ -13,24 +14,30 @@ const extractAndTransform = (code, template = "") => { const externalScriptTemplate = new Map(); -module.exports = () => ({ - name: "vuetify", - async transform(code, id) { - if (externalScriptTemplate.has(id)) { - return extractAndTransform(code, externalScriptTemplate.get(id)); - } else if (/.*\.vue/.test(id)) { - const source = await load(id); - - if (source.isExternalScript) { - externalScriptTemplate.set(source.scriptPath, source.template); - return; - } else if (/\.*vue\?rollup-plugin-vue=script((?!map).)*$/i.test(id) || !source.script) { - if (typeof source.script === "string" && source.script.trim() === "") { - code = "export default {}"; - } +module.exports = (options = {}) => { + const filter = createFilter(options.include, options.exclude); + + return { + name: "vuetify", + async transform (code, id) { + if (!filter(id)) return null; + + if (externalScriptTemplate.has(id)) { + return extractAndTransform(code, externalScriptTemplate.get(id)); + } else if (/.*\.vue/.test(id)) { + const source = await load(id); + + if (source.isExternalScript) { + externalScriptTemplate.set(source.scriptPath, source.template); + return; + } else if (/\.*vue\?rollup-plugin-vue=script((?!map).)*$/i.test(id) || !source.script) { + if (typeof source.script === "string" && source.script.trim() === "") { + code = "export default {}"; + } - return extractAndTransform(code, source.template); + return extractAndTransform(code, source.template); + } } - } - }, -}); + }, + } +};