@dword-design/base-config-nuxt 4.0.15 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js ADDED
@@ -0,0 +1,24 @@
1
+ import dotenv from '@dword-design/dotenv-json-extended';
2
+ import jitiBabelTransform from '@dword-design/jiti-babel-transform';
3
+ import jiti from 'jiti';
4
+ dotenv.config();
5
+ let config;
6
+ try {
7
+ const jitiInstance = jiti(process.cwd(), {
8
+ esmResolve: true,
9
+ interopDefault: true,
10
+ transform: jitiBabelTransform
11
+ });
12
+ config = jitiInstance('./config.js');
13
+ } catch (error) {
14
+ if (error.message.startsWith("Cannot find module './config.js'\n")) {
15
+ config = {};
16
+ } else {
17
+ throw error;
18
+ }
19
+ }
20
+ export default {
21
+ name: 'Vue app',
22
+ userScalable: true,
23
+ ...config
24
+ };
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { globby } from 'globby';
7
7
  import { createRequire } from 'module';
8
8
  import outputFiles from 'output-files';
9
9
  import P from 'path';
10
+ import { fileURLToPath } from 'url';
10
11
  import analyze from "./analyze.js";
11
12
  import depcheckSpecial from "./depcheck-special.js";
12
13
  import dev from "./dev.js";
@@ -14,7 +15,9 @@ import eslintConfig from "./eslint.config.js";
14
15
  import lint from "./lint.js";
15
16
  import prepublishOnly from "./prepublish-only.js";
16
17
  import start from "./start.js";
18
+ const __dirname = P.dirname(fileURLToPath(import.meta.url));
17
19
  const _require = createRequire(import.meta.url);
20
+ const isInNodeModules = __dirname.split(P.sep).includes('node_modules');
18
21
  export default {
19
22
  allowedMatches: ['.stylelintrc.json', 'server/api/**/*.js', 'server/middleware/**/*.js', 'assets', 'components', 'content', 'i18n', 'layouts', 'middleware', 'model', 'modules', 'config.js', 'pages', 'plugins', 'public', 'store', 'types'],
20
23
  commands: {
@@ -40,13 +43,14 @@ export default {
40
43
  main: 'dist/index.js'
41
44
  },
42
45
  prepare: async () => {
43
- const projectModulePath = `./${P.relative(process.cwd(), _require.resolve('./modules/project/index.js')).split(P.sep).join('/')}`;
46
+ const configPath = isInNodeModules ? '@dword-design/base-config-nuxt/config' : `./${P.relative(process.cwd(), _require.resolve('./config.js')).split(P.sep).join('/')}`;
47
+ const parentConfigPath = isInNodeModules ? '@dword-design/base-config-nuxt/nuxt.config' : `./${P.relative(process.cwd(), _require.resolve('./nuxt.config.js')).split(P.sep).join('/')}`;
44
48
  const translations = await globby('i18n/*.json');
45
49
  const hasI18n = translations.length > 0;
46
50
  await outputFiles({
47
- '.stylelintrc.json': JSON.stringify({
51
+ '.stylelintrc.json': `${JSON.stringify({
48
52
  extends: packageName`@dword-design/stylelint-config`
49
- }, undefined, 2),
53
+ }, undefined, 2)}\n`,
50
54
  'app.vue': endent`
51
55
  <template>
52
56
  <NuxtLayout>
@@ -68,77 +72,15 @@ export default {
68
72
  meta: i18nHead.value.meta,
69
73
  `] : []), "titleTemplate: title => title ? `${title} | ${runtimeConfig.public.name}` : `${runtimeConfig.public.name}${runtimeConfig.public.title ? `: ${runtimeConfig.public.title}` : ''}`"].join('\n')}
70
74
  })
71
- </script>
75
+ </script>\n
72
76
  `,
73
77
  'nuxt.config.js': javascript`
74
- import projectModule from '${projectModulePath}'
75
- import jiti from 'jiti'
76
- import dotenv from '@dword-design/dotenv-json-extended'
77
- import jitiBabelTransform from '@dword-design/jiti-babel-transform'
78
- import { transform } from '@babel/core'
79
- import { babel as rollupPluginBabel } from '${packageName`@rollup/plugin-babel`}'
80
- import { parse } from 'vue/compiler-sfc'
81
- import vueSfcDescriptorToString from '${packageName`vue-sfc-descriptor-to-string`}'
82
- import { parseVueRequest } from '@vitejs/plugin-vue'
83
- import P from 'path'
84
-
85
- dotenv.config()
86
-
87
- let options
88
- try {
89
- const jitiInstance = jiti(process.cwd(), {
90
- esmResolve: true,
91
- interopDefault: true,
92
- transform: jitiBabelTransform,
93
- })
94
- options = jitiInstance('./config.js')
95
- } catch (error) {
96
- if (error.message.startsWith("Cannot find module './config.js'\\n")) {
97
- options = {}
98
- } else {
99
- throw error
100
- }
101
- }
78
+ import config from '${configPath}'
102
79
 
103
80
  export default {
104
- nitro: {
105
- rollupConfig: {
106
- plugins: [rollupPluginBabel({ babelHelpers: 'bundled' })],
107
- },
108
- },
109
- modules: [
110
- [projectModule, options],
111
- ],
112
- vite: {
113
- plugins: [
114
- {
115
- enforce: 'pre',
116
- transform: async (code, id) => {
117
- const query = parseVueRequest(id)
118
- if (query.filename.endsWith('.vue') && !query.filename.split('/').includes('node_modules')) {
119
- const sfc = parse(code)
120
- for (const section of ['scriptSetup', 'script']) {
121
- if (sfc.descriptor[section] && sfc.descriptor[section].lang === undefined) {
122
- sfc.descriptor[section].content = await transform(sfc.descriptor[section].content, {
123
- plugins: [['@babel/plugin-proposal-pipeline-operator', { proposal: 'fsharp' }]]
124
- }).code
125
- }
126
- }
127
- return vueSfcDescriptorToString(sfc.descriptor)
128
- }
129
- return code
130
- },
131
- }
132
- ],
133
- vue: {
134
- template: {
135
- transformAssetUrls: {
136
- includeAbsolute: false,
137
- },
138
- },
139
- },
140
- },
141
- }
81
+ extends: '${parentConfigPath}',
82
+ ...config,
83
+ }\n
142
84
  `
143
85
  });
144
86
  },
@@ -0,0 +1,105 @@
1
+ import { transform } from '@babel/core';
2
+ import { babel as rollupPluginBabel } from '@rollup/plugin-babel';
3
+ import { parseVueRequest } from '@vitejs/plugin-vue';
4
+ import { parse } from '@vue/compiler-sfc';
5
+ import packageName from 'depcheck-package-name';
6
+ import vueSfcDescriptorToString from 'vue-sfc-descriptor-to-string';
7
+ import config from "./config.js";
8
+ // import expressModule from './modules/express/index.js'
9
+ import i18nModule from "./modules/i18n/index.js";
10
+ import localeLinkModule from "./modules/locale-link/index.js";
11
+ import svgModule from "./modules/svg.js";
12
+ const isBasicAuthEnabled = process.env.BASIC_AUTH_USER && process.env.BASIC_AUTH_PASSWORD;
13
+ export default {
14
+ app: {
15
+ head: {
16
+ meta: [{
17
+ content: config.name,
18
+ hid: 'description',
19
+ name: 'description'
20
+ }, ...(config.webApp ? [{
21
+ content: 'yes',
22
+ name: 'apple-mobile-web-app-capable'
23
+ }] : []), ...(config.ogImage ? [{
24
+ content: config.ogImage,
25
+ hid: 'og:image',
26
+ name: 'og:image'
27
+ }] : [])]
28
+ }
29
+ },
30
+ modules: [(otpoins, nuxt) => {
31
+ if (!config.userScalable) {
32
+ const viewportMeta = nuxt.options.app.head.meta.find(meta => meta.name === 'viewport');
33
+ viewportMeta.content += ', user-scalable=0';
34
+ }
35
+ }, [packageName`nuxt-basic-authentication-module`, {
36
+ enabled: !!isBasicAuthEnabled
37
+ }], [packageName`@nuxtjs/eslint-module`, {
38
+ cache: false,
39
+ failOnWarning: true,
40
+ fix: true,
41
+ lintOnStart: false
42
+ }], [packageName`@nuxtjs/stylelint-module`, {
43
+ allowEmptyInput: true,
44
+ failOnWarning: true,
45
+ fix: true,
46
+ lintOnStart: false
47
+ }], i18nModule,
48
+ // expressModule,
49
+ svgModule, localeLinkModule],
50
+ nitro: {
51
+ rollupConfig: {
52
+ plugins: [rollupPluginBabel({
53
+ babelHelpers: 'bundled'
54
+ })]
55
+ }
56
+ },
57
+ router: {
58
+ options: {
59
+ linkActiveClass: 'active'
60
+ }
61
+ },
62
+ runtimeConfig: {
63
+ public: {
64
+ name: config.name,
65
+ title: config.title
66
+ },
67
+ ...(isBasicAuthEnabled && {
68
+ basicAuth: {
69
+ pairs: {
70
+ [process.env.BASIC_AUTH_USER]: process.env.BASIC_AUTH_PASSWORD
71
+ }
72
+ }
73
+ })
74
+ },
75
+ vite: {
76
+ plugins: [{
77
+ enforce: 'pre',
78
+ transform: async (code, id) => {
79
+ const query = parseVueRequest(id);
80
+ if (query.filename.endsWith('.vue') && !query.filename.split('/').includes('node_modules')) {
81
+ const sfc = parse(code);
82
+ for (const section of ['scriptSetup', 'script']) {
83
+ if (sfc.descriptor[section] && sfc.descriptor[section].lang === undefined) {
84
+ sfc.descriptor[section].content = await transform(sfc.descriptor[section].content, {
85
+ plugins: [['@babel/plugin-proposal-pipeline-operator', {
86
+ proposal: 'fsharp'
87
+ }]]
88
+ }).code;
89
+ }
90
+ }
91
+ return vueSfcDescriptorToString(sfc.descriptor);
92
+ }
93
+ return code;
94
+ }
95
+ }],
96
+ vue: {
97
+ template: {
98
+ transformAssetUrls: {
99
+ includeAbsolute: false
100
+ }
101
+ }
102
+ }
103
+ },
104
+ watch: ['config.js']
105
+ };
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@dword-design/base-config-nuxt",
3
- "version": "4.0.15",
3
+ "version": "5.0.1",
4
4
  "repository": "dword-design/base-config-nuxt",
5
5
  "funding": "https://github.com/sponsors/dword-design",
6
6
  "license": "MIT",
7
7
  "author": "Sebastian Landwehr <info@sebastianlandwehr.com>",
8
8
  "type": "module",
9
- "exports": "./dist/index.js",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./config": "./dist/config.js",
12
+ "./nuxt.config": "./dist/nuxt.config.js"
13
+ },
10
14
  "main": "dist/index.js",
11
15
  "files": [
12
16
  "dist"
@@ -21,10 +25,8 @@
21
25
  "prepublishOnly": "base prepublishOnly",
22
26
  "test": "base test"
23
27
  },
24
- "resolutions": {
25
- "stylelint/cosmiconfig": "8.1.3"
26
- },
27
28
  "dependencies": {
29
+ "@babel/core": "^7.22.5",
28
30
  "@dword-design/depcheck-parser-sass": "^4.0.0",
29
31
  "@dword-design/dotenv-json-extended": "^2.0.0",
30
32
  "@dword-design/functions": "^4.0.0",
@@ -35,6 +37,8 @@
35
37
  "@nuxtjs/i18n": "npm:@dword-design/nuxt-i18n",
36
38
  "@nuxtjs/stylelint-module": "^5.0.1",
37
39
  "@rollup/plugin-babel": "^6.0.3",
40
+ "@vitejs/plugin-vue": "^4.2.3",
41
+ "@vue/compiler-sfc": "^3.3.4",
38
42
  "depcheck-package-name": "^3.0.0",
39
43
  "depcheck-parser-vue": "^4.0.7",
40
44
  "execa": "^7.1.1",
@@ -1,103 +0,0 @@
1
- import omit from "@dword-design/functions/dist/omit.js";
2
- import { addPlugin, addTemplate, installModule } from '@nuxt/kit';
3
- import packageName from 'depcheck-package-name';
4
- import { createRequire } from 'module';
5
- import P from 'path';
6
-
7
- // import expressModule from './modules/express/index.js'
8
- import i18nModule from "./modules/i18n/index.js";
9
- import localeLinkModule from "./modules/locale-link/index.js";
10
- import svgModule from "./modules/svg.js";
11
- const _require = createRequire(import.meta.url);
12
- export default (async (options, nuxt) => {
13
- const defaultConfig = {
14
- bodyAttrs: {},
15
- css: [],
16
- head: {},
17
- headAttrs: {},
18
- htmlAttrs: {},
19
- modules: [],
20
- name: 'Vue app',
21
- plugins: [],
22
- router: {},
23
- userScalable: true
24
- };
25
- const projectConfig = {
26
- ...defaultConfig,
27
- ...options,
28
- css: [...defaultConfig.css, ...(options.css || [])]
29
- };
30
- nuxt.options.watch.push('config.js');
31
- nuxt.options.runtimeConfig.public.name = projectConfig.name;
32
- nuxt.options.runtimeConfig.public.title = projectConfig.title;
33
- if (process.env.BASIC_AUTH_USER && process.env.BASIC_AUTH_PASSWORD) {
34
- nuxt.options.runtimeConfig.basicAuth = {
35
- pairs: {
36
- [process.env.BASIC_AUTH_USER]: process.env.BASIC_AUTH_PASSWORD
37
- }
38
- };
39
- }
40
- nuxt.options.app.head.link.push(...(projectConfig.head.link || []));
41
- nuxt.options.app.head.meta.push({
42
- content: projectConfig.name,
43
- hid: 'description',
44
- name: 'description'
45
- });
46
- if (!projectConfig.userScalable) {
47
- const viewportMeta = nuxt.options.app.head.meta.find(meta => meta.name === 'viewport');
48
- viewportMeta.content += ', user-scalable=0';
49
- }
50
- if (projectConfig.ogImage) {
51
- nuxt.options.app.head.meta.push({
52
- content: projectConfig.ogImage,
53
- hid: 'og:image',
54
- name: 'og:image'
55
- });
56
- }
57
- if (projectConfig.webApp) {
58
- nuxt.options.app.head.meta.push({
59
- content: 'yes',
60
- name: 'apple-mobile-web-app-capable'
61
- });
62
- }
63
- nuxt.options.app.head.htmlAttrs = projectConfig.htmlAttrs;
64
- nuxt.options.app.head.bodyAttrs = projectConfig.bodyAttrs;
65
- nuxt.options.css.push(...projectConfig.css);
66
- Object.assign(nuxt.options.router.options, {
67
- linkActiveClass: 'active',
68
- ...projectConfig.router
69
- });
70
- Object.assign(nuxt.options, omit(Object.keys({
71
- ...defaultConfig,
72
- ...nuxt.options
73
- }))(projectConfig));
74
- const modules = [[packageName`nuxt-basic-authentication-module`, {
75
- enabled: nuxt.options.runtimeConfig.basicAuth !== undefined
76
- }], [packageName`@nuxtjs/eslint-module`, {
77
- cache: false,
78
- failOnWarning: true,
79
- fix: true,
80
- lintOnStart: false
81
- }], [packageName`@nuxtjs/stylelint-module`, {
82
- allowEmptyInput: true,
83
- failOnWarning: true,
84
- fix: true,
85
- lintOnStart: false
86
- }], i18nModule,
87
- // expressModule,
88
- svgModule, localeLinkModule, ...(projectConfig.modules || [])];
89
- for (let module of modules) {
90
- module = [].concat(module);
91
- await installModule(module[0], module[1]);
92
- }
93
- addTemplate({
94
- fileName: P.join('project', 'project-config.js'),
95
- options: projectConfig,
96
- src: _require.resolve('./project-config.js.template')
97
- });
98
- for (const plugin of projectConfig.plugins) {
99
- addPlugin(plugin, {
100
- append: true
101
- });
102
- }
103
- });
@@ -1 +0,0 @@
1
- export default <%= JSON.stringify(options) %>
File without changes