From 5ebf1cc78c565671d25766bae58a30a5a46427c7 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 6 May 2019 15:16:04 +0430 Subject: [PATCH] fix: avoid using aliases in templates (#5656) --- packages/builder/src/context/template.js | 2 ++ .../test/context/__snapshots__/template.test.js.snap | 3 +++ packages/builder/test/context/template.test.js | 1 + packages/vue-app/template/middleware.js | 2 +- packages/vue-app/template/store.js | 6 +++--- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/context/template.js b/packages/builder/src/context/template.js index bf55ff4221..e5abefad2c 100644 --- a/packages/builder/src/context/template.js +++ b/packages/builder/src/context/template.js @@ -39,6 +39,8 @@ export default class TemplateContext { : options.loading, pageTransition: options.pageTransition, layoutTransition: options.layoutTransition, + rootDir: options.rootDir, + srcDir: options.srcDir, dir: options.dir, components: { ErrorPage: options.ErrorPage diff --git a/packages/builder/test/context/__snapshots__/template.test.js.snap b/packages/builder/test/context/__snapshots__/template.test.js.snap index 7c96dd8676..a2b215e23a 100644 --- a/packages/builder/test/context/__snapshots__/template.test.js.snap +++ b/packages/builder/test/context/__snapshots__/template.test.js.snap @@ -74,6 +74,7 @@ TemplateContext { "pageTransition": Object { "name": "test_trans", }, + "rootDir": "test_root_dir", "router": Object { "route": "test", }, @@ -90,12 +91,14 @@ TemplateContext { "plugins": Array [ "plugins", ], + "rootDir": "test_root_dir", "router": Object { "route": "test", }, "splitChunks": Object { "testSC": true, }, + "srcDir": "test_src_dir", "store": "test_store", "uniqBy": [Function], "vue": Object { diff --git a/packages/builder/test/context/template.test.js b/packages/builder/test/context/template.test.js index b070395b0a..aa099be03d 100644 --- a/packages/builder/test/context/template.test.js +++ b/packages/builder/test/context/template.test.js @@ -36,6 +36,7 @@ describe('builder: buildContext', () => { 'test-layout': 'test.template' }, srcDir: 'test_src_dir', + rootDir: 'test_root_dir', loading: 'test-loading', pageTransition: { name: 'test_trans' }, layoutTransition: { name: 'test_layout_trans' }, diff --git a/packages/vue-app/template/middleware.js b/packages/vue-app/template/middleware.js index 2fcd5c62f3..1d5ec453aa 100644 --- a/packages/vue-app/template/middleware.js +++ b/packages/vue-app/template/middleware.js @@ -2,7 +2,7 @@ const middleware = {} <% middleware.forEach(m => { 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 %>'] <% }) %> export default middleware diff --git a/packages/vue-app/template/store.js b/packages/vue-app/template/store.js index 62ef6854c5..46ecd29eac 100644 --- a/packages/vue-app/template/store.js +++ b/packages/vue-app/template/store.js @@ -10,7 +10,7 @@ let store = {} void (function updateModules() { <% storeModules.some(s => { 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 }}) %> // If store is an exported method = classic mode (deprecated) @@ -24,14 +24,14 @@ void (function updateModules() { <% storeModules.forEach(s => { 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 (isDev) { %> if (process.client && module.hot) { // Whenever any Vuex module is updated... module.hot.accept([<% storeModules.forEach(s => { %> - '@/<%= dir.store %>/<%= s.src %>',<% }) %> + '<%= relativeToBuild(srcDir, dir.store, s.src) %>',<% }) %> ], () => { // Update `root.modules` with the latest definitions. updateModules()