-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt-module)!: extend nuxt config (#1428)
* feat(nuxt-module): extend nuxt config method with default config * refactor(cli): remove unused nuxt.config.js upgrade after init * docs: update docs with feature info
- Loading branch information
Showing
10 changed files
with
236 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 5 additions & 53 deletions
58
packages/cli/src/templates/project-template/nuxt.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,9 @@ | ||
export default { | ||
telemetry: false, | ||
env: { | ||
CHOKIDAR_USEPOLLING: process.env.NODE_ENV == 'production' ? 0 : 1, | ||
}, | ||
server: { | ||
port: process.env.PORT || 3000, | ||
host: process.env.HOST || '0.0.0.0', | ||
}, | ||
// Global page headers: https://go.nuxtjs.dev/config-head | ||
import { extendNuxtConfig } from '@shopware-pwa/nuxt-module' | ||
|
||
export default extendNuxtConfig({ | ||
head: { | ||
title: 'shopware-pwa-project', | ||
meta: [ | ||
{ hid: 'project-type', name: 'project-type', content: 'shopware-pwa' }, | ||
{ charset: 'utf-8' }, | ||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }, | ||
{ hid: 'description', name: 'description', content: '' }, | ||
], | ||
meta: [{ hid: 'description', name: 'description', content: '' }], | ||
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }], | ||
}, | ||
|
||
// Global CSS: https://go.nuxtjs.dev/config-css | ||
css: ['~assets/scss/main.scss'], | ||
|
||
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins | ||
plugins: [], | ||
|
||
// Auto import components: https://go.nuxtjs.dev/config-components | ||
components: false, | ||
|
||
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules | ||
buildModules: ['@shopware-pwa/nuxt-module'], | ||
|
||
// Modules: https://go.nuxtjs.dev/config-modules | ||
modules: [ | ||
// https://go.nuxtjs.dev/axios | ||
'@nuxtjs/axios', | ||
// https://go.nuxtjs.dev/pwa | ||
'@nuxtjs/pwa', | ||
], | ||
|
||
// Axios module configuration: https://go.nuxtjs.dev/config-axios | ||
axios: {}, | ||
|
||
// PWA module configuration: https://go.nuxtjs.dev/pwa | ||
pwa: { | ||
manifest: { | ||
lang: 'en', | ||
}, | ||
workbox: { | ||
offlineStrategy: 'StaleWhileRevalidate', | ||
}, | ||
}, | ||
|
||
// Build Configuration: https://go.nuxtjs.dev/config-build | ||
build: {}, | ||
} | ||
}) |
71 changes: 71 additions & 0 deletions
71
packages/nuxt-module/__tests__/__snapshots__/config.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`nuxt-module - extendNuxtConfig should return default config 1`] = ` | ||
Object { | ||
"axios": Object {}, | ||
"build": Object {}, | ||
"buildModules": Array [ | ||
"@shopware-pwa/nuxt-module", | ||
], | ||
"components": false, | ||
"css": Array [ | ||
"~assets/scss/main.scss", | ||
], | ||
"env": Object { | ||
"CHOKIDAR_USEPOLLING": "1", | ||
"EXPERIMENTAL_IMAGE_PROCESSING_SERVER": "", | ||
}, | ||
"head": Object { | ||
"link": Array [ | ||
Object { | ||
"href": "/favicon.ico", | ||
"rel": "icon", | ||
"type": "image/x-icon", | ||
}, | ||
], | ||
"meta": Array [ | ||
Object { | ||
"content": "shopware-pwa", | ||
"hid": "project-type", | ||
"name": "project-type", | ||
}, | ||
Object { | ||
"content": "shopware-pwa", | ||
"hid": "project-type", | ||
"name": "project-type", | ||
}, | ||
Object { | ||
"charset": "utf-8", | ||
}, | ||
Object { | ||
"content": "width=device-width, initial-scale=1", | ||
"name": "viewport", | ||
}, | ||
Object { | ||
"content": "", | ||
"hid": "description", | ||
"name": "description", | ||
}, | ||
], | ||
"title": "shopware-pwa-project", | ||
}, | ||
"modules": Array [ | ||
"@nuxtjs/axios", | ||
"@nuxtjs/pwa", | ||
], | ||
"plugins": Array [], | ||
"pwa": Object { | ||
"manifest": Object { | ||
"lang": "en", | ||
}, | ||
"workbox": Object { | ||
"offlineStrategy": "StaleWhileRevalidate", | ||
}, | ||
}, | ||
"server": Object { | ||
"host": "0.0.0.0", | ||
"port": 3000, | ||
}, | ||
"telemetry": false, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { extendNuxtConfig } from "../src/index"; | ||
|
||
describe("nuxt-module - extendNuxtConfig", () => { | ||
it("should return default config", () => { | ||
const result = extendNuxtConfig({}); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
it("should overwrite server port", () => { | ||
const result = extendNuxtConfig({ | ||
server: { | ||
port: 2000, | ||
}, | ||
}); | ||
expect(result.server?.port).toEqual(2000); | ||
}); | ||
|
||
it("should add new build module", () => { | ||
const result = extendNuxtConfig({ | ||
buildModules: ["some-new-module"], | ||
}); | ||
expect(result.buildModules).toEqual([ | ||
"@shopware-pwa/nuxt-module", | ||
"some-new-module", | ||
]); | ||
}); | ||
|
||
describe("env properties", () => { | ||
const ORIGINAL_ENV = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); // clears the cache | ||
process.env = { ...ORIGINAL_ENV }; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = ORIGINAL_ENV; | ||
}); | ||
|
||
it("should pass env properties to config", () => { | ||
process.env.NODE_ENV = "production"; | ||
process.env.EXPERIMENTAL_IMAGE_PROCESSING_SERVER = "https://example.com"; | ||
|
||
const { extendNuxtConfig } = require("../src/index"); | ||
const result = extendNuxtConfig({}); | ||
|
||
expect(result.env?.CHOKIDAR_USEPOLLING).toEqual("0"); | ||
expect(result.env?.EXPERIMENTAL_IMAGE_PROCESSING_SERVER).toEqual( | ||
"https://example.com" | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
381a32a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: