Skip to content

Commit

Permalink
reverting change to only package vue runtime loader
Browse files Browse the repository at this point in the history
This makes it harder for beginners and it's hard to know the fix.
As a compromise, this alerts (on a production build) that there is
an option to choose a smaller build.
  • Loading branch information
weaverryan committed May 13, 2020
1 parent ce8d221 commit 1d959fd
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 23 deletions.
23 changes: 2 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,8 @@

## 0.30.0

* [BC BREAK] The Vue "build" was changed from `vue.esm.js` (full build) to
`vue.runtime.esm.js` (runtime build). With the runtime build, there are
two things that you cannot do:

A) You cannot pass a string to `template`:

```js
new Vue({
template: '<div>{{ hi }}</div>'
})
```

B) You cannot mount to a DOM element and use its HTML as your template:

```js
new Vue({
el: '#app', // where <div id="app"> contains your Vue template
});
```

If you need this behavior, call `Encore.addAliases({ vue$: 'vue/dist/vue.esm.js' });`
* ~~[BC BREAK] The Vue "build" was changed from `vue.esm.js` (full build) to `vue.runtime.esm.js` (runtime build)~~
This was reverted in Encore 0.30.1.

* [DEPENDENCY UPGRADE] `sass-loader` was upgraded from version 7 to 8.
See the [CHANGELOG](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md#800-2019-08-29)
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,11 @@ class Encore {
* Encore.enableVueLoader(() => {}, {
* // set optional Encore-specific options, for instance:
*
* // defaults to true, set to false to *only* include
* // the smaller "runtime" build, which can't compile
* // templates at runtime.
* runtimeCompilerBuild: true
*
* // use version 2 or 3 to force your Vue version
* // otherwise, Encore will detect it automatically
* version: 2
Expand Down
1 change: 1 addition & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class WebpackConfig {
this.vueOptions = {
useJsx: false,
version: null,
runtimeCompilerBuild: true
};
this.eslintOptions = {
lintVue: false,
Expand Down
20 changes: 20 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ const PluginPriorities = require('./plugins/plugin-priorities');
const applyOptionsCallback = require('./utils/apply-options-callback');
const sharedEntryTmpName = require('./utils/sharedEntryTmpName');
const copyEntryTmpName = require('./utils/copyEntryTmpName');
const getVueVersion = require('./utils/get-vue-version');
const tmp = require('tmp');
const fs = require('fs');
const path = require('path');
const stringEscaper = require('./utils/string-escaper');
const crypto = require('crypto');
const logger = require('./logger');
const chalk = require('chalk');
const os = require('os');

class ConfigGenerator {
Expand Down Expand Up @@ -100,6 +102,24 @@ class ConfigGenerator {
alias: {}
};

if (this.webpackConfig.useVueLoader && this.webpackConfig.vueOptions.runtimeCompilerBuild) {
if (this.webpackConfig.isProduction()) {
logger.recommendation(`If you do not need to compile Vue templates at runtime, pass ${chalk.green('{ runtimeCompilerBuild: false }')} as the 3rd argument to ${chalk.green('enableVueLoader()')} for a smaller build.`);
}

const vueVersion = getVueVersion(this.webpackConfig);
switch (vueVersion) {
case 2:
config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
break;
case 3:
config.resolve.alias['vue'] = 'vue/dist/vue.esm-bundler.js';
break;
default:
throw new Error(`Invalid vue version ${vueVersion}`);
}
}

if (this.webpackConfig.usePreact && this.webpackConfig.preactOptions.preactCompat) {
config.resolve.alias['react'] = 'preact-compat';
config.resolve.alias['react-dom'] = 'preact-compat';
Expand Down
2 changes: 1 addition & 1 deletion lib/friendly-errors/transformers/missing-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function isErrorFromVueLoader(filename) {
}

// vue3
if (filename.includes('vue-loader/dist??')) {
if (/vue-loader\/dist(\/index\.js)?\?\?/.test(filename)) {
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/manifest-key-prefix-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unus
module.exports = function(webpackConfig) {
let manifestPrefix = webpackConfig.manifestKeyPrefix;
if (null === manifestPrefix) {
if (null === webpackConfig.publicPath) {
throw new Error('publicPath is not set on WebpackConfig');
}

// by convention, we remove the opening slash on the manifest keys
manifestPrefix = webpackConfig.publicPath.replace(/^\//, '');
}
Expand Down
3 changes: 2 additions & 1 deletion test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ describe('WebpackConfig object', () => {
config.enableVueLoader(() => {}, {
notExisting: false,
});
}).to.throw('"notExisting" is not a valid key for enableVueLoader(). Valid keys: useJsx, version.');
}).to.throw('"notExisting" is not a valid key for enableVueLoader(). Valid keys: useJsx, version, runtimeCompilerBuild.');
});

it('Should set Encore-specific options', () => {
Expand All @@ -1049,6 +1049,7 @@ describe('WebpackConfig object', () => {
});

expect(config.vueOptions).to.deep.equal({
runtimeCompilerBuild: true,
useJsx: true,
version: null,
});
Expand Down
28 changes: 28 additions & 0 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,34 @@ describe('The config-generator function', () => {
});
});

describe('enableVueLoader() with runtimeCompilerBuild sets Vue alias', () => {
it('defaults to true', () => {
const config = createConfig();
config.outputPath = '/tmp/output/public-path';
config.publicPath = '/public-path';
config.enableSingleRuntimeChunk();
config.enableVueLoader(() => {}, { version: 3 });

const actualConfig = configGenerator(config);

expect(actualConfig.resolve.alias).to.deep.equals({
'vue': 'vue/dist/vue.esm-bundler.js',
});
});

it('no alias for false', () => {
const config = createConfig();
config.outputPath = '/tmp/output/public-path';
config.publicPath = '/public-path';
config.enableSingleRuntimeChunk();
config.enableVueLoader(() => {}, { version: 3, runtimeCompilerBuild: false });

const actualConfig = configGenerator(config);

expect(actualConfig.resolve.alias).to.deep.empty;
});
});

describe('addAliases() adds new aliases', () => {
it('without addAliases()', () => {
const config = createConfig();
Expand Down

0 comments on commit 1d959fd

Please sign in to comment.