From 360d82c13daed5a921d5c324d3af7dd2a6945531 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Sun, 24 May 2020 03:54:00 +0200 Subject: [PATCH] Resolve npm modules from root app (#617) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow requiring node modules from the root project folder. Previously, custom Vue components could only use npm packages installed by Twill itself. With this change, any npm package from the main app can be required. We do this by adding the root `npm_modules` folder to webpack’s module resolver. Should be backwards-compatible since Twill’s `node_modules` folder still has preference. Default resolve order: `['node_modules']`. New resolve order: `['node_modules', '../../../node_modules']` Co-authored-by: Quentin Renard --- vue.config.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vue.config.js b/vue.config.js index 27e811e60..f549ab2ba 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,3 +1,4 @@ +const fs = require("fs") const path = require('path') const isProd = process.env.NODE_ENV === 'production' @@ -91,6 +92,13 @@ if (!isProd) { })) } +// Define npm module resolve order: 1. local (Twill), 2. root (App) +const appModuleFolder = path.resolve(__dirname, '../../../node_modules') // vendor/area17/twill/ +const resolveModules = ['node_modules'] +if (fs.existsSync(appModuleFolder)) { + resolveModules.push(appModuleFolder) +} + const config = { // Define base outputDir of build outputDir: outputDir, @@ -123,7 +131,8 @@ const config = { 'prosemirror-state' : path.join(__dirname, 'node_modules/prosemirror-state/src/index.js'), 'prosemirror-view' : path.join(__dirname, 'node_modules/prosemirror-view/src/index.js'), 'prosemirror-transform' : path.join(__dirname, 'node_modules/prosemirror-transform/src/index.js') - } + }, + modules: resolveModules }, plugins, performance: {