fix: avoid using aliases in templates (#5656)

This commit is contained in:
Pooya Parsa 2019-05-06 15:16:04 +04:30 committed by GitHub
parent 86c7fe8841
commit 5ebf1cc78c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 4 deletions

View File

@ -39,6 +39,8 @@ export default class TemplateContext {
: options.loading, : options.loading,
pageTransition: options.pageTransition, pageTransition: options.pageTransition,
layoutTransition: options.layoutTransition, layoutTransition: options.layoutTransition,
rootDir: options.rootDir,
srcDir: options.srcDir,
dir: options.dir, dir: options.dir,
components: { components: {
ErrorPage: options.ErrorPage ErrorPage: options.ErrorPage

View File

@ -74,6 +74,7 @@ TemplateContext {
"pageTransition": Object { "pageTransition": Object {
"name": "test_trans", "name": "test_trans",
}, },
"rootDir": "test_root_dir",
"router": Object { "router": Object {
"route": "test", "route": "test",
}, },
@ -90,12 +91,14 @@ TemplateContext {
"plugins": Array [ "plugins": Array [
"plugins", "plugins",
], ],
"rootDir": "test_root_dir",
"router": Object { "router": Object {
"route": "test", "route": "test",
}, },
"splitChunks": Object { "splitChunks": Object {
"testSC": true, "testSC": true,
}, },
"srcDir": "test_src_dir",
"store": "test_store", "store": "test_store",
"uniqBy": [Function], "uniqBy": [Function],
"vue": Object { "vue": Object {

View File

@ -36,6 +36,7 @@ describe('builder: buildContext', () => {
'test-layout': 'test.template' 'test-layout': 'test.template'
}, },
srcDir: 'test_src_dir', srcDir: 'test_src_dir',
rootDir: 'test_root_dir',
loading: 'test-loading', loading: 'test-loading',
pageTransition: { name: 'test_trans' }, pageTransition: { name: 'test_trans' },
layoutTransition: { name: 'test_layout_trans' }, layoutTransition: { name: 'test_layout_trans' },

View File

@ -2,7 +2,7 @@ const middleware = {}
<% middleware.forEach(m => { <% middleware.forEach(m => {
const name = m.src.replace(new RegExp(`\\.(${extensions})$`), '') const name = m.src.replace(new RegExp(`\\.(${extensions})$`), '')
%> %>
middleware['<%= name %>'] = require('@/<%= dir.middleware %>/<%= m.src %>'); middleware['<%= name %>'] = require('<%= relativeToBuild(srcDir, dir.middleware, m.src) %>');
middleware['<%= name %>'] = middleware['<%= name %>'].default || middleware['<%= name %>'] middleware['<%= name %>'] = middleware['<%= name %>'].default || middleware['<%= name %>']
<% }) %> <% }) %>
export default middleware export default middleware

View File

@ -10,7 +10,7 @@ let store = {}
void (function updateModules() { void (function updateModules() {
<% storeModules.some(s => { <% storeModules.some(s => {
if(s.src.indexOf('index.') === 0) { %> if(s.src.indexOf('index.') === 0) { %>
store = normalizeRoot(require('@/<%= dir.store %>/<%= s.src %>'), '<%= dir.store %>/<%= s.src %>') store = normalizeRoot(require('<%= relativeToBuild(srcDir, dir.store, s.src) %>'), '<%= dir.store %>/<%= s.src %>')
<% return true }}) %> <% return true }}) %>
// If store is an exported method = classic mode (deprecated) // If store is an exported method = classic mode (deprecated)
@ -24,14 +24,14 @@ void (function updateModules() {
<% storeModules.forEach(s => { <% storeModules.forEach(s => {
if(s.src.indexOf('index.') !== 0) { %> if(s.src.indexOf('index.') !== 0) { %>
resolveStoreModules(require('@/<%= dir.store %>/<%= s.src %>'), '<%= s.src %>')<% }}) %> resolveStoreModules(require('<%= relativeToBuild(srcDir, dir.store, s.src) %>'), '<%= s.src %>')<% }}) %>
// If the environment supports hot reloading... // If the environment supports hot reloading...
<% if (isDev) { %> <% if (isDev) { %>
if (process.client && module.hot) { if (process.client && module.hot) {
// Whenever any Vuex module is updated... // Whenever any Vuex module is updated...
module.hot.accept([<% storeModules.forEach(s => { %> module.hot.accept([<% storeModules.forEach(s => { %>
'@/<%= dir.store %>/<%= s.src %>',<% }) %> '<%= relativeToBuild(srcDir, dir.store, s.src) %>',<% }) %>
], () => { ], () => {
// Update `root.modules` with the latest definitions. // Update `root.modules` with the latest definitions.
updateModules() updateModules()