diff --git a/.eslintignore b/.eslintignore index 75702544c6..9998e3fe6c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,3 +5,5 @@ packages/boilerplate/composables/nuxt/plugin.js packages/commercetools/composables/nuxt/plugin.js packages/core/cache/nuxt/plugin.js +packages/core/nuxt-module/plugins/i18n-cookies.js +packages/core/nuxt-module/plugins/logger.js diff --git a/package.json b/package.json index e925137621..1da57c8539 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,11 @@ "build:bp:composables": "cd packages/boilerplate/composables && yarn build", "build:bp:theme": "cd packages/boilerplate/theme && yarn build", "build:bp:tools": "yarn build:core && yarn build:bp:api-client && yarn build:bp:composables", - "build:core": "yarn build:core:core && yarn build:core:cache && yarn build:core:middleware", + "build:core": "yarn build:core:core && yarn build:core:cache && yarn build:core:middleware && yarn build:core:nuxt-module", "build:core:core": "cd packages/core/core && yarn build", "build:core:cache": "cd packages/core/cache && yarn build", "build:core:middleware": "cd packages/core/middleware && yarn build", + "build:core:nuxt-module": "cd packages/core/nuxt-module && yarn build", "build:ct": "yarn build:ct:tools && yarn build:ct:theme", "build:ct:api-client": "cd packages/commercetools/api-client && yarn build", "build:ct:composables": "cd packages/commercetools/composables && yarn build", diff --git a/packages/core/docs/architecture/application-context.md b/packages/core/docs/architecture/application-context.md index 2460ebe5f7..c2d630fabd 100644 --- a/packages/core/docs/architecture/application-context.md +++ b/packages/core/docs/architecture/application-context.md @@ -1,6 +1,6 @@ # Application context -An application context is an object available in the Nuxt.js application. +An application context is an object available in the Nuxt.js application. Plugins and modules registered in the `nuxt.config.js` file populate this object and add integration-specific data under a unique key. The Nuxt.js application later uses this information to send requests to the Server Middleware. ## Structure of the context diff --git a/packages/core/docs/changelog/6641.js b/packages/core/docs/changelog/6641.js new file mode 100644 index 0000000000..6c3aa76e99 --- /dev/null +++ b/packages/core/docs/changelog/6641.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'Added the ability to select plugins used by @vue-storefront/nuxt', + link: 'https://github.com/vuestorefront/vue-storefront/pull/6641', + isBreaking: false, + breakingChanges: [], + author: 'Mateusz PietrusiƄski', + linkToGitHubAccount: 'https://github.com/Mateuszpietrusinski' +}; diff --git a/packages/core/docs/package.json b/packages/core/docs/package.json index e81d7aa52a..f931e9f2cb 100644 --- a/packages/core/docs/package.json +++ b/packages/core/docs/package.json @@ -10,8 +10,9 @@ "core-cache-ref": "cd ../cache && api-extractor run --local", "core-core-ref": "cd ../core && api-extractor run --local", "core-middleware-ref": "cd ../middleware && api-extractor run --local", + "core-nuxt-module-ref": "cd ../nuxt-module && api-extractor run --local", "core-ref-md": "api-documenter markdown --i reference/api --o reference/api", - "build:core": "yarn core-cache-ref && yarn core-core-ref && yarn core-middleware-ref && yarn core-ref-md" + "build:core": "yarn core-cache-ref && yarn core-core-ref && yarn core-middleware-ref && yarn core-nuxt-module-ref && yarn core-ref-md" }, "devDependencies": { "@microsoft/api-documenter": "^7.13.7", diff --git a/packages/core/nuxt-module/.gitignore b/packages/core/nuxt-module/.gitignore index c434d59719..491fc35975 100644 --- a/packages/core/nuxt-module/.gitignore +++ b/packages/core/nuxt-module/.gitignore @@ -1,2 +1,2 @@ node_modules -!lib +lib diff --git a/packages/core/nuxt-module/api-extractor.json b/packages/core/nuxt-module/api-extractor.json new file mode 100644 index 0000000000..de0db2df60 --- /dev/null +++ b/packages/core/nuxt-module/api-extractor.json @@ -0,0 +1,10 @@ +{ + "extends": "../../api-extractor.base.json", + "mainEntryPointFilePath": "./lib/src/api-extractor-data.d.ts", + "dtsRollup": { + "untrimmedFilePath": "./lib/.d.ts" + }, + "docModel": { + "apiJsonFilePath": "/core/docs/reference/api/.api.json" + } +} diff --git a/packages/core/nuxt-module/lib/helpers/isProduction.js b/packages/core/nuxt-module/lib/helpers/isProduction.js deleted file mode 100644 index e71474aecb..0000000000 --- a/packages/core/nuxt-module/lib/helpers/isProduction.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = (options) => process.env.NODE_ENV === 'production' || options.coreDevelopment; \ No newline at end of file diff --git a/packages/core/nuxt-module/lib/helpers/log.js b/packages/core/nuxt-module/lib/helpers/log.js deleted file mode 100644 index 63caa034d2..0000000000 --- a/packages/core/nuxt-module/lib/helpers/log.js +++ /dev/null @@ -1,9 +0,0 @@ -const consola = require('consola'); -const chalk = require('chalk'); - -module.exports = Object.freeze({ - info: (message) => consola.info(chalk.bold('VSF'), message), - success: (message) => consola.success(chalk.bold('VSF'), message), - warning: (message) => consola.warning(chalk.bold('VSF'), message), - error: (message) => consola.error(chalk.bold('VSF'), message) -}); diff --git a/packages/core/nuxt-module/lib/helpers/merge.js b/packages/core/nuxt-module/lib/helpers/merge.js deleted file mode 100644 index 4d1599b6f7..0000000000 --- a/packages/core/nuxt-module/lib/helpers/merge.js +++ /dev/null @@ -1,7 +0,0 @@ -const { mergeWith, isArray } = require('lodash'); - -module.exports = (source, destination) => mergeWith(source, destination, (objValue, srcValue) => { - if (isArray(objValue)) { - return objValue.concat(srcValue); - } -}); diff --git a/packages/core/nuxt-module/lib/helpers/resolveDependency.js b/packages/core/nuxt-module/lib/helpers/resolveDependency.js deleted file mode 100644 index 6d1474a007..0000000000 --- a/packages/core/nuxt-module/lib/helpers/resolveDependency.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function resolveDependency (name) { - try { - return require.resolve(name, { paths: [ process.cwd() ] }) - } catch (error) { - return false; - } -}; diff --git a/packages/core/nuxt-module/lib/module.js b/packages/core/nuxt-module/lib/module.js deleted file mode 100644 index bdb0989e8d..0000000000 --- a/packages/core/nuxt-module/lib/module.js +++ /dev/null @@ -1,93 +0,0 @@ -// TODO proper bundling, for now it's just to experiment with nuxt modules api -const fs = require('fs'); -const path = require('path'); -const log = require('./helpers/log'); -const merge = require('./helpers/merge'); -const resolveDependency = require('./helpers/resolveDependency'); -const performanceModule = require('./modules/performance'); -const storefrontUiModule = require('./modules/storefront-ui'); -const rawSourcesModule = require('./modules/raw-sources-loader'); - -module.exports = function VueStorefrontNuxtModule (moduleOptions) { - const defaultOptions = { - coreDevelopment: false, - performance: { - httpPush: true, - purgeCSS: { - enabled: false, - paths: [ - '**/*.vue' - ] - } - }, - useRawSource: { - dev: [], - prod: [] - } - }; - - const options = merge(defaultOptions, moduleOptions); - - // Add meta data - this.options.head.meta.push({ - name: 'generator', - content: 'Vue Storefront 2' - }); - - log.info('Starting Vue Storefront Nuxt Module'); - - // Enable HTTP/2 push for JS files - if (options.performance.httpPush) { - this.options.render = merge(this.options.render, { - http2: { - push: true, - pushAssets: (request, response, publicPath, preloadFiles) => { - return preloadFiles - .filter(({ asType }) => asType === 'script') - .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`); - } - } - }); - } - - // Context plugin - this.addPlugin(path.resolve(__dirname, 'plugins/context.js')) - log.success('Installed Vue Storefront Context plugin'); - - // SSR plugin - this.addPlugin(path.resolve(__dirname, 'plugins/ssr.js')); - log.success('Installed Vue Storefront SSR plugin'); - - // Logger plugin - this.addPlugin({ - src: path.resolve(__dirname, 'plugins/logger.js'), - options: moduleOptions.logger || {} - }); - log.success('Installed VSF Logger plugin'); - - // Context plugin - this.addPlugin(path.resolve(__dirname, 'plugins/e2e-testing.js')) - log.success('Installed Vue Storefront E2E testing plugin'); - - // i18n-cookies plugin - this.addPlugin({ - src: path.resolve(__dirname, 'plugins/i18n-cookies.js'), - options: this.options.i18n - }); - log.success('Installed Internationalization Cookies plugin'); - - // StorefrontUI module - if (fs.existsSync(resolveDependency('@storefront-ui/vue'))) { - storefrontUiModule.call(this, options); - log.success('Installed StorefrontUI Module'); - } - - // Performance module - performanceModule.call(this, options); - log.success('Installed Performance Module'); - - // Raw sources loader - rawSourcesModule.call(this, options); -}; - -module.exports.meta = require('../package.json'); diff --git a/packages/core/nuxt-module/lib/modules/raw-sources-loader.js b/packages/core/nuxt-module/lib/modules/raw-sources-loader.js deleted file mode 100644 index 9414e90559..0000000000 --- a/packages/core/nuxt-module/lib/modules/raw-sources-loader.js +++ /dev/null @@ -1,21 +0,0 @@ -const log = require('../helpers/log'); -const isProduction = require('../helpers/isProduction'); -const resolveDependency = require('../helpers/resolveDependency'); - -module.exports = function VueStorefrontPerformanceModule (options) { - const useRawSource = (package) => { - const pkgPath = resolveDependency(`${package}/package.json`); - const pkg = require(pkgPath); - - if (pkg.module) { - this.extendBuild(config => { - config.resolve.alias[pkg.name + '$'] = resolveDependency(`${package}/${pkg.module}`); - }); - } - - this.options.build.transpile.push(package); - log.info(`Using raw source/ESM for ${pkg.name}`); - }; - - options.useRawSource[isProduction(options) ? 'prod' : 'dev'].map(package => useRawSource(package)); -}; diff --git a/packages/core/nuxt-module/package.json b/packages/core/nuxt-module/package.json index 1c3503620c..45578f37b5 100644 --- a/packages/core/nuxt-module/package.json +++ b/packages/core/nuxt-module/package.json @@ -1,10 +1,13 @@ { "name": "@vue-storefront/nuxt", "version": "2.5.5", - "description": "", - "main": "lib/module.js", + "main": "lib/index.cjs.js", + "module": "lib/index.es.js", + "types": "lib/src/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "rimraf lib && rollup -c", + "test": "echo \"Error: no test specified\" && exit 1", + "prepublish": "yarn build" }, "author": "Vue Storefront", "license": "MIT", @@ -19,9 +22,14 @@ "nuxt-purgecss": "^1.0.0" }, "devDependencies": { - "@nuxt/types": "^2.15.8" + "@nuxt/types": "^2.15.8", + "@rollup/plugin-json": "~4.1.0" }, "publishConfig": { "access": "public" - } + }, + "files": [ + "lib/**/*", + "plugins/**/*" + ] } diff --git a/packages/core/nuxt-module/lib/plugins/context.js b/packages/core/nuxt-module/plugins/context.js similarity index 99% rename from packages/core/nuxt-module/lib/plugins/context.js rename to packages/core/nuxt-module/plugins/context.js index 824f949516..ca9efb6187 100644 --- a/packages/core/nuxt-module/lib/plugins/context.js +++ b/packages/core/nuxt-module/plugins/context.js @@ -1,4 +1,3 @@ - import { configureContext } from '@vue-storefront/core'; import { useContext as useBaseContext } from '@nuxtjs/composition-api'; diff --git a/packages/core/nuxt-module/lib/plugins/e2e-testing.js b/packages/core/nuxt-module/plugins/e2e-testing.js similarity index 69% rename from packages/core/nuxt-module/lib/plugins/e2e-testing.js rename to packages/core/nuxt-module/plugins/e2e-testing.js index 5d9b74bc2c..c1f288683c 100644 --- a/packages/core/nuxt-module/lib/plugins/e2e-testing.js +++ b/packages/core/nuxt-module/plugins/e2e-testing.js @@ -5,9 +5,9 @@ const e2eTestingPlugin = (ctx) => { bind: (element, binding) => { const enabled = ctx.isDev || ctx.env.NUXT_ENV_E2E === true.toString(); - return enabled && element.setAttribute(`data-e2e`, binding.value); + return enabled && element.setAttribute('data-e2e', binding.value); } }); }; -export default e2eTestingPlugin; \ No newline at end of file +export default e2eTestingPlugin; diff --git a/packages/core/nuxt-module/lib/plugins/i18n-cookies.js b/packages/core/nuxt-module/plugins/i18n-cookies.js similarity index 100% rename from packages/core/nuxt-module/lib/plugins/i18n-cookies.js rename to packages/core/nuxt-module/plugins/i18n-cookies.js diff --git a/packages/core/nuxt-module/lib/plugins/logger.js b/packages/core/nuxt-module/plugins/logger.js similarity index 100% rename from packages/core/nuxt-module/lib/plugins/logger.js rename to packages/core/nuxt-module/plugins/logger.js diff --git a/packages/core/nuxt-module/lib/plugins/ssr.js b/packages/core/nuxt-module/plugins/ssr.js similarity index 100% rename from packages/core/nuxt-module/lib/plugins/ssr.js rename to packages/core/nuxt-module/plugins/ssr.js diff --git a/packages/core/nuxt-module/rollup.config.js b/packages/core/nuxt-module/rollup.config.js new file mode 100644 index 0000000000..4f130762c5 --- /dev/null +++ b/packages/core/nuxt-module/rollup.config.js @@ -0,0 +1,36 @@ +import pkg from './package.json'; +import typescript from 'rollup-plugin-typescript2'; +import { terser } from 'rollup-plugin-terser'; +import json from '@rollup/plugin-json'; + +export function generateBaseConfig(pkg) { + return { + input: 'src/index.ts', + output: [ + { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + { + file: pkg.module, + format: 'es', + sourcemap: true + } + ], + external: [ + ...Object.keys(pkg.dependencies || {}) + ], + plugins: [ + typescript({ + // eslint-disable-next-line global-require + typescript: require('typescript'), + objectHashIgnoreUnknownHack: true + }), + terser(), + json() + ] + }; +} + +export default generateBaseConfig(pkg); diff --git a/packages/core/nuxt-module/src/api-extractor-data.ts b/packages/core/nuxt-module/src/api-extractor-data.ts new file mode 100644 index 0000000000..5d00d7abc6 --- /dev/null +++ b/packages/core/nuxt-module/src/api-extractor-data.ts @@ -0,0 +1,11 @@ +/** + * Core Vue Storefront 2 nuxt module. + * + * @remarks + * The `@vue-storefront/nuxt` library is responsible for loading core nuxt plugins. + * + * @packageDocumentation + */ + +export { default as VueStorefrontNuxtModule } from './index'; +export { ModuleOptions } from './types'; diff --git a/packages/core/nuxt-module/src/helpers/isProduction.ts b/packages/core/nuxt-module/src/helpers/isProduction.ts new file mode 100644 index 0000000000..97d0fc3de8 --- /dev/null +++ b/packages/core/nuxt-module/src/helpers/isProduction.ts @@ -0,0 +1,3 @@ +import { ModuleOptions } from '../types'; + +export default (options: ModuleOptions): boolean => process.env.NODE_ENV === 'production' || options.coreDevelopment; diff --git a/packages/core/nuxt-module/src/helpers/log.ts b/packages/core/nuxt-module/src/helpers/log.ts new file mode 100644 index 0000000000..13d44e4fba --- /dev/null +++ b/packages/core/nuxt-module/src/helpers/log.ts @@ -0,0 +1,12 @@ +import consola from 'consola'; +import chalk from 'chalk'; +import { Log } from '../types'; + +const log: Log = Object.freeze({ + info: (message) => consola.info(chalk.bold('VSF'), message), + success: (message) => consola.success(chalk.bold('VSF'), message), + warning: (message) => consola.warn(chalk.bold('VSF'), message), + error: (message) => consola.error(chalk.bold('VSF'), message) +}); + +export default log; diff --git a/packages/core/nuxt-module/src/helpers/merge.ts b/packages/core/nuxt-module/src/helpers/merge.ts new file mode 100644 index 0000000000..e909056044 --- /dev/null +++ b/packages/core/nuxt-module/src/helpers/merge.ts @@ -0,0 +1,7 @@ +import { mergeWith, isArray } from 'lodash'; + +export default (source, destination) => mergeWith(source, destination, (objValue, srcValue) => { + if (isArray(objValue)) { + return objValue.concat(srcValue); + } +}); diff --git a/packages/core/nuxt-module/src/helpers/resolveDependency.ts b/packages/core/nuxt-module/src/helpers/resolveDependency.ts new file mode 100644 index 0000000000..cd50628576 --- /dev/null +++ b/packages/core/nuxt-module/src/helpers/resolveDependency.ts @@ -0,0 +1,7 @@ +export default function resolveDependency(name: string): string { + try { + return require.resolve(name, { paths: [process.cwd()] }); + } catch (error) { + return ''; + } +} diff --git a/packages/core/nuxt-module/src/index.ts b/packages/core/nuxt-module/src/index.ts new file mode 100644 index 0000000000..2888eb41e2 --- /dev/null +++ b/packages/core/nuxt-module/src/index.ts @@ -0,0 +1,110 @@ +// TODO proper bundling, for now it's just to experiment with nuxt modules api +import fs from 'fs'; +import path from 'path'; +import log from './helpers/log'; +import merge from './helpers/merge'; +import resolveDependency from './helpers/resolveDependency'; +import performanceModule from './modules/performance'; +import storefrontUiModule from './modules/storefront-ui'; +import rawSourcesModule from './modules/raw-sources-loader'; +import { ModuleOptions } from './types'; + +export { default as meta } from '../package.json'; + +/** + * VueStorefrontNuxtModule + * @param moduleOptions + */ +export default function VueStorefrontNuxtModule(moduleOptions: ModuleOptions) { + const defaultOptions = { + coreDevelopment: false, + i18nExtension: true, + e2e: true, + logger: true, + ssr: true, + context: true, + sfui: true, + performance: { + httpPush: true, + purgeCSS: { + enabled: false, + paths: ['**/*.vue'] + } + }, + useRawSource: { + dev: [], + prod: [] + } + }; + + const options = merge(defaultOptions, moduleOptions); + + // Add meta data + this.options.head.meta.push({ + name: 'generator', + content: 'Vue Storefront 2' + }); + + log.info('Starting Vue Storefront Nuxt Module'); + + // Enable HTTP/2 push for JS files + if (options.performance.httpPush) { + this.options.render = merge(this.options.render, { + http2: { + push: true, + pushAssets: (request, response, publicPath, preloadFiles) => { + return preloadFiles + .filter(({ asType }) => asType === 'script') + .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`); + } + } + }); + } + if (options.context) { + // Context plugin + this.addPlugin(path.resolve(__dirname, '../plugins/context.js')); + log.success('Installed Vue Storefront Context plugin'); + } + if (options.ssr) { + // SSR plugin + this.addPlugin(path.resolve(__dirname, '../plugins/ssr.js')); + log.success('Installed Vue Storefront SSR plugin'); + } + + if (options.logger) { + // Logger plugin + this.addPlugin({ + src: path.resolve(__dirname, '../plugins/logger.js'), + options: moduleOptions.logger || {} + }); + log.success('Installed VSF Logger plugin'); + } + + if (options.e2e) { + // Context plugin + this.addPlugin(path.resolve(__dirname, '../plugins/e2e-testing.js')); + log.success('Installed Vue Storefront E2E testing plugin'); + } + + // i18n-cookies plugin + if (options.i18nExtension) { + this.addPlugin({ + src: path.resolve(__dirname, '../plugins/i18n-cookies.js'), + options: this.options.i18n + }); + log.success('Installed Internationalization Cookies plugin'); + } + + // StorefrontUI module + if (fs.existsSync(resolveDependency('@storefront-ui/vue')) && options.sfui) { + storefrontUiModule.call(this, options); + log.success('Installed StorefrontUI Module'); + } + + // Performance module + performanceModule.call(this, options); + log.success('Installed Performance Module'); + + // Raw sources loader + rawSourcesModule.call(this, options); +} diff --git a/packages/core/nuxt-module/lib/modules/performance.js b/packages/core/nuxt-module/src/modules/performance.ts similarity index 68% rename from packages/core/nuxt-module/lib/modules/performance.js rename to packages/core/nuxt-module/src/modules/performance.ts index 905e5b478c..0b3b072fee 100644 --- a/packages/core/nuxt-module/lib/modules/performance.js +++ b/packages/core/nuxt-module/src/modules/performance.ts @@ -1,6 +1,7 @@ -const { merge } = require('lodash'); +import { merge } from 'lodash'; +import { ModuleOptions, PurgeCSSOptions } from '../types'; -function pushScripts() { +function pushScripts(): void { this.options.render = merge(this.options.render, { http2: { push: true, @@ -13,12 +14,12 @@ function pushScripts() { }); } -function loadPurgeCss(options) { +function loadPurgeCss(options: PurgeCSSOptions): void { // PurgeCSS module should be installed after all other modules - this.nuxt.hook('modules:done', moduleContainer => moduleContainer.addModule([ 'nuxt-purgecss', options ])); + this.nuxt.hook('modules:done', moduleContainer => moduleContainer.addModule(['nuxt-purgecss', options])); } -module.exports = function VueStorefrontPerformanceModule (options) { +export default function VueStorefrontPerformanceModule(options: ModuleOptions): void { const { httpPush, purgeCSS } = options.performance; if (httpPush) { @@ -28,4 +29,4 @@ module.exports = function VueStorefrontPerformanceModule (options) { if (purgeCSS && purgeCSS.enabled) { loadPurgeCss.call(this, purgeCSS); } -}; +} diff --git a/packages/core/nuxt-module/src/modules/raw-sources-loader.ts b/packages/core/nuxt-module/src/modules/raw-sources-loader.ts new file mode 100644 index 0000000000..47c1933d06 --- /dev/null +++ b/packages/core/nuxt-module/src/modules/raw-sources-loader.ts @@ -0,0 +1,23 @@ +import log from '../helpers/log'; +import isProduction from '../helpers/isProduction'; +import resolveDependency from '../helpers/resolveDependency'; +import { ModuleOptions } from '../types'; + +export default function VueStorefrontPerformanceModule(options: ModuleOptions): void { + const useRawSource = (pckg) => { + const pkgPath = resolveDependency(`${pckg}/package.json`); + // eslint-disable-next-line global-require + const pkg = require(pkgPath || ''); + + if (pkg.module) { + this.extendBuild(config => { + config.resolve.alias[pkg.name + '$'] = resolveDependency(`${pckg}/${pkg.module}`); + }); + } + + this.options.build.transpile.push(pckg); + log.info(`Using raw source/ESM for ${pkg.name}`); + }; + + options.useRawSource[isProduction(options) ? 'prod' : 'dev'].map(pckg => useRawSource(pckg)); +} diff --git a/packages/core/nuxt-module/lib/modules/storefront-ui.js b/packages/core/nuxt-module/src/modules/storefront-ui.ts similarity index 55% rename from packages/core/nuxt-module/lib/modules/storefront-ui.js rename to packages/core/nuxt-module/src/modules/storefront-ui.ts index 8a405c7f87..5ef2a852be 100644 --- a/packages/core/nuxt-module/lib/modules/storefront-ui.js +++ b/packages/core/nuxt-module/src/modules/storefront-ui.ts @@ -1,7 +1,8 @@ -const merge = require('../helpers/merge'); +import merge from '../helpers/merge'; +import { ModuleOptions } from '../types'; // TODO: Create a separate nuxt module for storefront ui -function loadStorefrontRawSources (options) { +function loadStorefrontRawSources(options: ModuleOptions): void { const rawSources = [ '@storefront-ui/vue', '@storefront-ui/shared' @@ -13,6 +14,6 @@ function loadStorefrontRawSources (options) { }); } -module.exports = function VueStorefrontPerformanceModule (options) { +export default function VueStorefrontPerformanceModule(options: ModuleOptions): void { loadStorefrontRawSources.call(this, options); -}; +} diff --git a/packages/core/nuxt-module/src/types.ts b/packages/core/nuxt-module/src/types.ts new file mode 100644 index 0000000000..594bef003d --- /dev/null +++ b/packages/core/nuxt-module/src/types.ts @@ -0,0 +1,29 @@ +export interface PurgeCSSOptions { + enabled?: boolean; + paths?: string[]; +} + +export interface ModuleOptions { + coreDevelopment?: boolean; + i18nExtension?: boolean; + e2e?: boolean; + logger?: boolean; + ssr?: boolean; + context?: boolean; + sfui?: boolean; + performance?: { + httpPush?: boolean; + purgeCSS?: PurgeCSSOptions; + }; + useRawSource?: { + dev: string[]; + prod: string[]; + }; +} + +export interface Log { + info: (message: string) => void; + success: (message: string) => void; + warning: (message: string) => void; + error: (message: string) => void; +} diff --git a/packages/core/nuxt-module/tsconfig.json b/packages/core/nuxt-module/tsconfig.json new file mode 100644 index 0000000000..fa3d04cdd8 --- /dev/null +++ b/packages/core/nuxt-module/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "outDir": "./lib", + "esModuleInterop": true, + "target": "es5", + "module": "ES2015", + "moduleResolution": "node", + "importHelpers": true, + "noEmitHelpers": true, + "sourceMap": true, + "declaration": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": "./", + "lib": ["es6", "es7", "dom"], + "strict": false, + "allowJs": true, + "resolveJsonModule": true + }, + "exclude": ["node_modules", "**/*.spec.ts"], + "include": ["src/**/*"] +} diff --git a/yarn.lock b/yarn.lock index 41d5f50573..8a7d9a4b07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3478,6 +3478,13 @@ "@rollup/pluginutils" "^4.0.0" graphql-tag "^2.2.2" +"@rollup/plugin-json@~4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3" + integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw== + dependencies: + "@rollup/pluginutils" "^3.0.8" + "@rollup/plugin-node-resolve@^13.0.6": version "13.0.6" resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.0.6.tgz#29629070bb767567be8157f575cfa8f2b8e9ef77" @@ -3498,7 +3505,7 @@ "@rollup/pluginutils" "^3.1.0" magic-string "^0.25.7" -"@rollup/pluginutils@^3.1.0": +"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==