mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
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:
parent
16898f8cfa
commit
5af65527b0
@ -447,7 +447,7 @@ export default class Builder {
|
|||||||
|
|
||||||
// Check plugins exist then set alias to their real path
|
// Check plugins exist then set alias to their real path
|
||||||
await Promise.all(this.plugins.map(async (p) => {
|
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}`)
|
const pluginFiles = await glob(`${p.src}${ext}`)
|
||||||
|
|
||||||
if (!pluginFiles || pluginFiles.length === 0) {
|
if (!pluginFiles || pluginFiles.length === 0) {
|
||||||
|
7
test/fixtures/basic/nuxt.config.js
vendored
7
test/fixtures/basic/nuxt.config.js
vendored
@ -8,9 +8,6 @@ export default {
|
|||||||
maxAge: ((60 * 60 * 24 * 365) * 2)
|
maxAge: ((60 * 60 * 24 * 365) * 2)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
|
||||||
'~/plugins/vuex-module'
|
|
||||||
],
|
|
||||||
router: {
|
router: {
|
||||||
extendRoutes(routes, resolve) {
|
extendRoutes(routes, resolve) {
|
||||||
return [{
|
return [{
|
||||||
@ -64,6 +61,10 @@ export default {
|
|||||||
'': true
|
'': true
|
||||||
},
|
},
|
||||||
transition: false,
|
transition: false,
|
||||||
|
plugins: [
|
||||||
|
'~/plugins/vuex-module',
|
||||||
|
'~/plugins/dir-plugin'
|
||||||
|
],
|
||||||
build: {
|
build: {
|
||||||
scopeHoisting: true,
|
scopeHoisting: true,
|
||||||
postcss: [
|
postcss: [
|
||||||
|
3
test/fixtures/basic/plugins/dir-plugin/index.js
vendored
Normal file
3
test/fixtures/basic/plugins/dir-plugin/index.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
if (process.client) {
|
||||||
|
window.__test_plugin = true
|
||||||
|
}
|
25
test/unit/basic.plugins.test.js
Normal file
25
test/unit/basic.plugins.test.js
Normal 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()
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user