Skip to content
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

Reverting change to only package vue runtime loader #769

Merged
merged 3 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ class Encore {
* Encore.enableVueLoader(() => {}, {
* // set optional Encore-specific options, for instance:
*
* // set to false to *only* include the smaller "runtime"
* // build, which can't compile templates at runtime, but it
weaverryan marked this conversation as resolved.
Show resolved Hide resolved
* // CSP compliant/
* // set explicitly to true to silence the recommendation
* runtimeCompilerBuild: false
*
* // 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: null
};
this.eslintOptions = {
lintVue: false,
Expand Down
19 changes: 19 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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');
Expand Down Expand Up @@ -100,6 +101,24 @@ class ConfigGenerator {
alias: {}
};

if (this.webpackConfig.useVueLoader && (this.webpackConfig.vueOptions.runtimeCompilerBuild === true || this.webpackConfig.vueOptions.runtimeCompilerBuild === null)) {
if (this.webpackConfig.vueOptions.runtimeCompilerBuild === null) {
logger.recommendation('To create a smaller (and CSP-compliant) build, see https://symfony.com/doc/current/frontend/encore/vuejs.html#runtime-compiler-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
6 changes: 5 additions & 1 deletion lib/friendly-errors/transformers/missing-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function isErrorFromVueLoader(filename) {
}

// vue3
if (filename.includes('vue-loader/dist??')) {
if (/vue-loader\/dist(\/index\.js)?\?\?/.test(filename)) {
return true;
}
// later vue3 variant
if (filename.includes('?vue') && filename.includes('lang=')) {
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');
weaverryan marked this conversation as resolved.
Show resolved Hide resolved
}

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