Skip to content

Add vue loader #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ module.exports = {
return this;
},

/**
* If enabled, the vue-loader is added:
* https://vue-loader.vuejs.org/en/
*
* @param {object} options see https://vue-loader.vuejs.org/en/configurations/advanced.html
* @return {exports}
*/
enableVueLoader(options = {}) {
webpackConfig.enableVueLoader(options);

return this;
},

/**
* If enabled, the output directory is emptied between
* each build (to remove old files).
Expand Down
7 changes: 7 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class WebpackConfig {
resolve_url_loader: true
};
this.useLessLoader = false;
this.useVueLoader = false;
this.vueOptions = {};
this.cleanupOutput = false;
this.sharedCommonsEntryName = null;
this.providedVariables = {};
Expand Down Expand Up @@ -222,6 +224,11 @@ class WebpackConfig {
this.useReact = true;
}

enableVueLoader(options) {
this.useVueLoader = true;
this.vueOptions = options;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change options to be a callback, like we do with configureBabel()? The reason is that we will (in order to extract styles) add a bunch of options to the loader automatically. If the user wants to add even more options, we'll want them to do that in callback (we'll pass them our options, then they can change/add them).


cleanupOutputBeforeBuild() {
this.cleanupOutput = true;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ class ConfigGenerator {
});
}

if (this.webpackConfig.useVueLoader) {
loaderFeatures.ensureLoaderPackagesExist('vue');

rules.push({
test: /\.vue/,
loader: 'vue-loader',
options: this.webpackConfig.vueOptions
});
}

this.webpackConfig.loaders.forEach((loader) => {
rules.push(loader);
});
Expand Down
5 changes: 5 additions & 0 deletions lib/loader-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const loaderFeatures = {
method: 'enableReactPreset()',
packages: ['babel-preset-react'],
description: 'process React JS files'
},
vue: {
method: 'enableVueLoader()',
packages: ['vue-loader', 'vue-template-compiler'],
description: 'load VUE files'
}
};

Expand Down
17 changes: 17 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,23 @@ describe('WebpackConfig object', () => {
});
});

describe('enableVueLoader', () => {
it('Call with no config', () => {
const config = createConfig();
config.enableVueLoader();

expect(config.useVueLoader).to.be.true;
});

it('Pass config', () => {
const config = createConfig();
config.enableVueLoader({ extractCSS: true });

expect(config.useVueLoader).to.be.true;
expect(config.vueOptions.extractCSS).to.be.true;
});
});

describe('addPlugin', () => {
it('extends the current registered plugins', () => {
const config = createConfig();
Expand Down