Skip to content

Commit adbadc3

Browse files
committed
bug #769 Reverting change to only package vue runtime loader (weaverryan)
This PR was squashed before being merged into the master branch. Discussion ---------- Reverting change to only package vue runtime loader Using the runtime build by default makes it harder for beginners and it's hard to know the fix. Specifically, if you follow the "intro docs" to Vue, you will likely try this: ```js var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' } }) ``` which will not work (and the error will be tough for beginners to spot). As a compromise, on a production build, we print a recommendation so that people can discover the option to use the smaller build. Commits ------- 6ae0aaa Update index.js 47f5ca3 Updating missing-loader for changing vue internal file syntax 1b393eb reverting change to only package vue runtime loader
2 parents ce8d221 + 6ae0aaa commit adbadc3

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,12 @@ class Encore {
11501150
* Encore.enableVueLoader(() => {}, {
11511151
* // set optional Encore-specific options, for instance:
11521152
*
1153+
* // set to false to *only* include the smaller "runtime"
1154+
* // build, which can't compile templates at runtime, but is
1155+
* // CSP compliant/
1156+
* // set explicitly to true to silence the recommendation
1157+
* runtimeCompilerBuild: false
1158+
*
11531159
* // use version 2 or 3 to force your Vue version
11541160
* // otherwise, Encore will detect it automatically
11551161
* 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: null
140141
};
141142
this.eslintOptions = {
142143
lintVue: false,

lib/config-generator.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ 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');
@@ -100,6 +101,24 @@ class ConfigGenerator {
100101
alias: {}
101102
};
102103

104+
if (this.webpackConfig.useVueLoader && (this.webpackConfig.vueOptions.runtimeCompilerBuild === true || this.webpackConfig.vueOptions.runtimeCompilerBuild === null)) {
105+
if (this.webpackConfig.vueOptions.runtimeCompilerBuild === null) {
106+
logger.recommendation('To create a smaller (and CSP-compliant) build, see https://symfony.com/doc/current/frontend/encore/vuejs.html#runtime-compiler-build');
107+
}
108+
109+
const vueVersion = getVueVersion(this.webpackConfig);
110+
switch (vueVersion) {
111+
case 2:
112+
config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
113+
break;
114+
case 3:
115+
config.resolve.alias['vue$'] = 'vue/dist/vue.esm-bundler.js';
116+
break;
117+
default:
118+
throw new Error(`Invalid vue version ${vueVersion}`);
119+
}
120+
}
121+
103122
if (this.webpackConfig.usePreact && this.webpackConfig.preactOptions.preactCompat) {
104123
config.resolve.alias['react'] = 'preact-compat';
105124
config.resolve.alias['react-dom'] = 'preact-compat';

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

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

3434
// vue3
35-
if (filename.includes('vue-loader/dist??')) {
35+
if (/vue-loader\/dist(\/index\.js)?\?\?/.test(filename)) {
36+
return true;
37+
}
38+
// later vue3 variant
39+
if (filename.includes('?vue') && filename.includes('lang=')) {
3640
return true;
3741
}
3842

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: null,
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)