allow plugin in directory with index.js file (#3908)

* allow plugin in directory with index.js file

* add test for plugin in dir

* fix: refacto plugins key
This commit is contained in:
Dmitry Molotkov 2018-09-18 19:06:55 +03:00 committed by Sébastien Chopin
parent 16898f8cfa
commit 5af65527b0
4 changed files with 33 additions and 4 deletions

View File

@ -447,7 +447,7 @@ export default class Builder {
// Check plugins exist then set alias to their real path
await Promise.all(this.plugins.map(async (p) => {
const ext = path.extname(p.src) ? '' : '.+([^.])'
const ext = path.extname(p.src) ? '' : '{.+([^.]),/index.+([^.])}'
const pluginFiles = await glob(`${p.src}${ext}`)
if (!pluginFiles || pluginFiles.length === 0) {

View File

@ -8,9 +8,6 @@ export default {
maxAge: ((60 * 60 * 24 * 365) * 2)
}
},
plugins: [
'~/plugins/vuex-module'
],
router: {
extendRoutes(routes, resolve) {
return [{
@ -64,6 +61,10 @@ export default {
'': true
},
transition: false,
plugins: [
'~/plugins/vuex-module',
'~/plugins/dir-plugin'
],
build: {
scopeHoisting: true,
postcss: [

View File

@ -0,0 +1,3 @@
if (process.client) {
window.__test_plugin = true
}

View File

@ -0,0 +1,25 @@
import { getPort, loadFixture, Nuxt } from '../utils'
let port
const url = route => 'http://localhost:' + port + route
let nuxt = null
describe('with-config', () => {
beforeAll(async () => {
const config = await loadFixture('basic')
nuxt = new Nuxt(config)
port = await getPort()
await nuxt.listen(port, 'localhost')
})
test('/', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
expect(window.__test_plugin).toBe(true)
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
})