Skip to content

Commit

Permalink
Add include and exclude options and update packages (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximStone authored Jan 5, 2022
1 parent 8c685f5 commit ef322f8
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 48 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
121 changes: 97 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
}
45 changes: 26 additions & 19 deletions src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { createFilter } = require("rollup-pluginutils");
const load = require("./load");
const extract = require("./extract");
const transform = require("./transform");
Expand All @@ -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);
}
}
}
},
});
},
}
};

0 comments on commit ef322f8

Please sign in to comment.