diff --git a/docs/index.md b/docs/index.md index 8e6504c556..df4cdd94a5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -28,7 +28,7 @@ You can also import individual module without bundling the full library. ```js static -import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar' +import NcAvatar from '@nextcloud/vue/components/NcAvatar' ``` ## Recommendations diff --git a/package-lock.json b/package-lock.json index c6ce73fba9..58d9ea42c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,7 +61,7 @@ "@nextcloud/browserslist-config": "^2.3.0", "@nextcloud/eslint-config": "^8.3.0-beta.0", "@nextcloud/stylelint-config": "^2.3.1", - "@nextcloud/vite-config": "^1.0.0-beta.17", + "@nextcloud/vite-config": "^1.0.0-beta.18", "@nextcloud/webpack-vue-config": "github:nextcloud/webpack-vue-config#master", "@vue/test-utils": "^1.3.0", "@vue/tsconfig": "^0.4.0", @@ -89,8 +89,7 @@ "vue-styleguidist": "~4.72.0", "vue-template-compiler": "^2.7.14", "webpack": "^5.88.1", - "webpack-merge": "^5.9.0", - "webpack-node-externals": "^3.0.0" + "webpack-merge": "^5.9.0" }, "engines": { "node": "^20.0.0", @@ -29212,15 +29211,6 @@ "node": ">=10.0.0" } }, - "node_modules/webpack-node-externals": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz", - "integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/webpack-sources": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-2.3.1.tgz", diff --git a/package.json b/package.json index 16ceb04755..4cc29a4cad 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,9 @@ "author": "John Molakvoæ (skjnldsv) ", "license": "AGPL-3.0", "scripts": { - "dev": "webpack --node-env development --progress", - "watch": "webpack --node-env development --progress --watch", - "watch:module": "vite build --mode development --watch", - "build": "webpack --node-env production --progress && npm run build:module", - "build:module": "vite --mode production build", + "build": "vite build --mode production ", + "dev": "vite build --mode development", + "dev:watch": "vite build --mode development --watch", "l10n:extract": "node build/extract-l10n.js", "lint": "eslint --ext .js,.vue src", "lint:fix": "eslint --ext .js,.vue src --fix", @@ -37,7 +35,22 @@ "import": "./dist/index.mjs", "require": "./dist/index.cjs" }, - "./dist/": "./dist/" + "./components/*": { + "import": "./dist/components/*.mjs", + "require": "./dist/components/*.cjs" + }, + "./directives/*": { + "import": "./dist/directives/*.mjs", + "require": "./dist/directives/*.cjs" + }, + "./functions/*": { + "import": "./dist/functions/*.mjs", + "require": "./dist/functions/*.cjs" + }, + "./mixins/*": { + "import": "./dist/mixins/*.mjs", + "require": "./dist/mixins/*.cjs" + } }, "files": [ "CHANGELOG.md", @@ -102,7 +115,7 @@ "@nextcloud/browserslist-config": "^2.3.0", "@nextcloud/eslint-config": "^8.3.0-beta.0", "@nextcloud/stylelint-config": "^2.3.1", - "@nextcloud/vite-config": "^1.0.0-beta.17", + "@nextcloud/vite-config": "^1.0.0-beta.18", "@nextcloud/webpack-vue-config": "github:nextcloud/webpack-vue-config#master", "@vue/test-utils": "^1.3.0", "@vue/tsconfig": "^0.4.0", @@ -130,8 +143,7 @@ "vue-styleguidist": "~4.72.0", "vue-template-compiler": "^2.7.14", "webpack": "^5.88.1", - "webpack-merge": "^5.9.0", - "webpack-node-externals": "^3.0.0" + "webpack-merge": "^5.9.0" }, "browserslist": [ "extends @nextcloud/browserslist-config" diff --git a/vite.config.mts b/vite.config.mts index f933b03ac7..273f6a676b 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -1,6 +1,7 @@ import type { Plugin } from 'vite' import { createLibConfig } from '@nextcloud/vite-config' -import { resolve } from 'path' +import { globSync } from 'glob' +import { join, resolve } from 'node:path' import { defineConfig } from 'vite' import md5 from 'md5' @@ -17,6 +18,38 @@ const TRANSLATIONS = await loadTranslations(resolve(__dirname, './l10n')) // Entry points which we build using vite const entryPoints = { + ...globSync('src/components/*/index.js').reduce((acc, item) => { + const name = item + .replace('/index.js', '') + .replace('src/components/', 'components/') + acc[name] = join(__dirname, item) + return acc + }, {}), + + ...globSync('src/directives/*/index.js').reduce((acc, item) => { + const name = item + .replace('/index.js', '') + .replace('src/directives/', 'directives/') + acc[name] = join(__dirname, item) + return acc + }, {}), + + ...globSync('src/functions/*/index.js').reduce((acc, item) => { + const name = item + .replace('/index.js', '') + .replace('src/functions/', 'functions/') + acc[name] = join(__dirname, item) + return acc + }, {}), + + ...globSync('src/mixins/*/index.js').reduce((acc, item) => { + const name = item + .replace('/index.js', '') + .replace('src/mixins/', 'mixins/') + acc[name] = join(__dirname, item) + return acc + }, {}), + index: resolve(__dirname, 'src/index.js'), } @@ -33,10 +66,6 @@ const vueDocsPlugin: Plugin = { // Customizations for the vite config const overrides = defineConfig({ - build: { - // Vite is run second so do not remove webpack files - emptyOutDir: false, - }, plugins: [ vueDocsPlugin, ], diff --git a/webpack.config.js b/webpack.config.js index bae3ec7a18..369db54ad3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,13 @@ +// config for the styleguide + const webpackConfig = require('@nextcloud/webpack-vue-config') const webpackRules = require('@nextcloud/webpack-vue-config/rules') -const { globSync } = require('glob') const md5 = require('md5') const path = require('path') const { DefinePlugin } = require('webpack') const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except') -const nodeExternals = require('webpack-node-externals') const { loadTranslations } = require('./build/translations.js') const buildMode = process.env.NODE_ENV @@ -19,55 +19,7 @@ const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud- const versionHash = md5(appVersion).slice(0, 7) const SCOPE_VERSION = JSON.stringify(versionHash) -console.info('This build version hash is', versionHash, '\n') - -webpackConfig.entry = { - ...globSync('src/components/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/components/', 'Components/') - acc[name] = path.join(__dirname, item) - return acc - }, {}), - - ...globSync('src/directives/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/directives/', 'Directives/') - acc[name] = path.join(__dirname, item) - return acc - }, {}), - - ...globSync('src/functions/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/functions/', 'Functions/') - acc[name] = path.join(__dirname, item) - return acc - }, {}), - - ...globSync('src/mixins/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/mixins/', 'Mixins/') - acc[name] = path.join(__dirname, item) - return acc - }, {}), -} - webpackConfig.devtool = isDev ? false : 'source-map' -webpackConfig.output = { - path: path.resolve(__dirname, './dist'), - publicPath: '/dist/', - filename: '[name].js', - library: { - type: 'umd', - name: ['NextcloudVue', '[name]'], - }, - umdNamedDefine: true, -} - -webpackConfig.externals = [nodeExternals()] webpackRules.RULE_SCSS = { test: /\.scss$/,