Skip to content

Commit

Permalink
Resolve npm modules from root app (area17#617)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
daun and ifox authored May 24, 2020
1 parent 8f5b0e2 commit 360d82c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require("fs")
const path = require('path')
const isProd = process.env.NODE_ENV === 'production'

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 360d82c

Please sign in to comment.