Skip to content

Commit 1d959fd

Browse files
committed
reverting change to only package vue runtime loader
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.
1 parent ce8d221 commit 1d959fd

File tree

8 files changed

+63
-23
lines changed

8 files changed

+63
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,8 @@
22

33
## 0.30.0
44

5-
* [BC BREAK] The Vue "build" was changed from `vue.esm.js` (full build) to
6-
`vue.runtime.esm.js` (runtime build). With the runtime build, there are
7-
two things that you cannot do:
8-
9-
A) You cannot pass a string to `template`:
10-
11-
```js
12-
new Vue({
13-
template: '<div>{{ hi }}</div>'
14-
})
15-
```
16-
17-
B) You cannot mount to a DOM element and use its HTML as your template:
18-
19-
```js
20-
new Vue({
21-
el: '#app', // where <div id="app"> contains your Vue template
22-
});
23-
```
24-
25-
If you need this behavior, call `Encore.addAliases({ vue$: 'vue/dist/vue.esm.js' });`
5+
* ~~[BC BREAK] The Vue "build" was changed from `vue.esm.js` (full build) to `vue.runtime.esm.js` (runtime build)~~
6+
This was reverted in Encore 0.30.1.
267

278
* [DEPENDENCY UPGRADE] `sass-loader` was upgraded from version 7 to 8.
289
See the [CHANGELOG](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md#800-2019-08-29)

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,11 @@ class Encore {
11501150
* Encore.enableVueLoader(() => {}, {
11511151
* // set optional Encore-specific options, for instance:
11521152
*
1153+
* // defaults to true, set to false to *only* include
1154+
* // the smaller "runtime" build, which can't compile
1155+
* // templates at runtime.
1156+
* runtimeCompilerBuild: true
1157+
*
11531158
* // use version 2 or 3 to force your Vue version
11541159
* // otherwise, Encore will detect it automatically
11551160
* version: 2

lib/WebpackConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class WebpackConfig {
137137
this.vueOptions = {
138138
useJsx: false,
139139
version: null,
140+
runtimeCompilerBuild: true
140141
};
141142
this.eslintOptions = {
142143
lintVue: false,

lib/config-generator.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ const PluginPriorities = require('./plugins/plugin-priorities');
4343
const applyOptionsCallback = require('./utils/apply-options-callback');
4444
const sharedEntryTmpName = require('./utils/sharedEntryTmpName');
4545
const copyEntryTmpName = require('./utils/copyEntryTmpName');
46+
const getVueVersion = require('./utils/get-vue-version');
4647
const tmp = require('tmp');
4748
const fs = require('fs');
4849
const path = require('path');
4950
const stringEscaper = require('./utils/string-escaper');
5051
const crypto = require('crypto');
5152
const logger = require('./logger');
53+
const chalk = require('chalk');
5254
const os = require('os');
5355

5456
class ConfigGenerator {
@@ -100,6 +102,24 @@ class ConfigGenerator {
100102
alias: {}
101103
};
102104

105+
if (this.webpackConfig.useVueLoader && this.webpackConfig.vueOptions.runtimeCompilerBuild) {
106+
if (this.webpackConfig.isProduction()) {
107+
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.`);
108+
}
109+
110+
const vueVersion = getVueVersion(this.webpackConfig);
111+
switch (vueVersion) {
112+
case 2:
113+
config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
114+
break;
115+
case 3:
116+
config.resolve.alias['vue'] = 'vue/dist/vue.esm-bundler.js';
117+
break;
118+
default:
119+
throw new Error(`Invalid vue version ${vueVersion}`);
120+
}
121+
}
122+
103123
if (this.webpackConfig.usePreact && this.webpackConfig.preactOptions.preactCompat) {
104124
config.resolve.alias['react'] = 'preact-compat';
105125
config.resolve.alias['react-dom'] = 'preact-compat';

lib/friendly-errors/transformers/missing-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function isErrorFromVueLoader(filename) {
3232
}
3333

3434
// vue3
35-
if (filename.includes('vue-loader/dist??')) {
35+
if (/vue-loader\/dist(\/index\.js)?\?\?/.test(filename)) {
3636
return true;
3737
}
3838

lib/utils/manifest-key-prefix-helper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unus
2020
module.exports = function(webpackConfig) {
2121
let manifestPrefix = webpackConfig.manifestKeyPrefix;
2222
if (null === manifestPrefix) {
23+
if (null === webpackConfig.publicPath) {
24+
throw new Error('publicPath is not set on WebpackConfig');
25+
}
26+
2327
// by convention, we remove the opening slash on the manifest keys
2428
manifestPrefix = webpackConfig.publicPath.replace(/^\//, '');
2529
}

test/WebpackConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ describe('WebpackConfig object', () => {
10391039
config.enableVueLoader(() => {}, {
10401040
notExisting: false,
10411041
});
1042-
}).to.throw('"notExisting" is not a valid key for enableVueLoader(). Valid keys: useJsx, version.');
1042+
}).to.throw('"notExisting" is not a valid key for enableVueLoader(). Valid keys: useJsx, version, runtimeCompilerBuild.');
10431043
});
10441044

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

10511051
expect(config.vueOptions).to.deep.equal({
1052+
runtimeCompilerBuild: true,
10521053
useJsx: true,
10531054
version: null,
10541055
});

test/config-generator.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,34 @@ describe('The config-generator function', () => {
447447
});
448448
});
449449

450+
describe('enableVueLoader() with runtimeCompilerBuild sets Vue alias', () => {
451+
it('defaults to true', () => {
452+
const config = createConfig();
453+
config.outputPath = '/tmp/output/public-path';
454+
config.publicPath = '/public-path';
455+
config.enableSingleRuntimeChunk();
456+
config.enableVueLoader(() => {}, { version: 3 });
457+
458+
const actualConfig = configGenerator(config);
459+
460+
expect(actualConfig.resolve.alias).to.deep.equals({
461+
'vue': 'vue/dist/vue.esm-bundler.js',
462+
});
463+
});
464+
465+
it('no alias for false', () => {
466+
const config = createConfig();
467+
config.outputPath = '/tmp/output/public-path';
468+
config.publicPath = '/public-path';
469+
config.enableSingleRuntimeChunk();
470+
config.enableVueLoader(() => {}, { version: 3, runtimeCompilerBuild: false });
471+
472+
const actualConfig = configGenerator(config);
473+
474+
expect(actualConfig.resolve.alias).to.deep.empty;
475+
});
476+
});
477+
450478
describe('addAliases() adds new aliases', () => {
451479
it('without addAliases()', () => {
452480
const config = createConfig();

0 commit comments

Comments
 (0)