Skip to content

Commit 59040a9

Browse files
committed
chore!: Migrate build of single entry points from webpack to vite
This is a breaking change as this also introduces ESM entry points for all components etc and therfor changed the files from `.js` to `.cjs` and `.mjs` respective. Instead of `import NcButton from '@nextcloud/vue/dist/Components/NcButton.js` use `import NcButton from '@nextcloud/vue/components/NcButton'`. * Also fix docs for component import pattern Co-authored-by: John Molakvoæ <[email protected]> Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 82160f9 commit 59040a9

File tree

5 files changed

+60
-78
lines changed

5 files changed

+60
-78
lines changed

package-lock.json

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
"author": "John Molakvoæ (skjnldsv) <[email protected]>",
1414
"license": "AGPL-3.0",
1515
"scripts": {
16-
"dev": "webpack --node-env development --progress && npm run dev:module",
17-
"dev:module": "vite build --mode development",
18-
"watch": "webpack --node-env development --progress --watch",
19-
"watch:module": "vite build --mode development --watch",
20-
"build": "webpack --node-env production --progress && npm run build:module",
21-
"build:module": "vite --mode production build",
16+
"build": "vite build --mode production ",
17+
"dev": "vite build --mode development",
18+
"dev:watch": "vite build --mode development --watch",
2219
"l10n:extract": "node build/extract-l10n.js",
2320
"lint": "eslint --ext .js,.vue src",
2421
"lint:fix": "eslint --ext .js,.vue src --fix",
@@ -38,7 +35,22 @@
3835
"import": "./dist/index.mjs",
3936
"require": "./dist/index.cjs"
4037
},
41-
"./dist/*": "./dist/*"
38+
"./dist/Components/*.js": {
39+
"import": "./dist/Components/*.mjs",
40+
"require": "./dist/Components/*.cjs"
41+
},
42+
"./dist/Directives/*.js": {
43+
"import": "./dist/Directives/*.mjs",
44+
"require": "./dist/Directives/*.cjs"
45+
},
46+
"./dist/Functions/*.js": {
47+
"import": "./dist/Functions/*.mjs",
48+
"require": "./dist/Functions/*.cjs"
49+
},
50+
"./dist/Mixins/*.js": {
51+
"import": "./dist/Mixins/*.mjs",
52+
"require": "./dist/Mixins/*.cjs"
53+
}
4254
},
4355
"files": [
4456
"CHANGELOG.md",
@@ -104,7 +116,7 @@
104116
"@nextcloud/browserslist-config": "^3.0.0",
105117
"@nextcloud/eslint-config": "^8.3.0-beta.0",
106118
"@nextcloud/stylelint-config": "^2.3.1",
107-
"@nextcloud/vite-config": "^1.0.0-beta.17",
119+
"@nextcloud/vite-config": "^1.0.0-beta.18",
108120
"@nextcloud/webpack-vue-config": "github:nextcloud/webpack-vue-config#master",
109121
"@vue/test-utils": "^1.3.0",
110122
"@vue/tsconfig": "^0.4.0",
@@ -132,8 +144,7 @@
132144
"vue-styleguidist": "~4.72.0",
133145
"vue-template-compiler": "^2.7.14",
134146
"webpack": "^5.88.1",
135-
"webpack-merge": "^5.9.0",
136-
"webpack-node-externals": "^3.0.0"
147+
"webpack-merge": "^5.9.0"
137148
},
138149
"browserslist": [
139150
"extends @nextcloud/browserslist-config"

styleguide.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = async () => {
5656
components: 'src/components/*/*.vue',
5757
getComponentPathLine(componentPath) {
5858
const name = path.basename(componentPath, '.vue')
59-
return `import ${name} from '@nextcloud/vue/dist/Components/${name}'`
59+
return `import ${name} from '@nextcloud/vue/dist/Components/${name}.js'`
6060
},
6161

6262
sections: [

vite.config.mts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Plugin } from 'vite'
22
import { createLibConfig } from '@nextcloud/vite-config'
3-
import { resolve } from 'path'
3+
import { globSync } from 'glob'
4+
import { join, resolve } from 'node:path'
45
import { defineConfig } from 'vite'
56

67
import md5 from 'md5'
@@ -17,6 +18,38 @@ const TRANSLATIONS = await loadTranslations(resolve(__dirname, './l10n'))
1718

1819
// Entry points which we build using vite
1920
const entryPoints = {
21+
...globSync('src/components/*/index.js').reduce((acc, item) => {
22+
const name = item
23+
.replace('/index.js', '')
24+
.replace('src/components/', 'Components/')
25+
acc[name] = join(__dirname, item)
26+
return acc
27+
}, {}),
28+
29+
...globSync('src/directives/*/index.js').reduce((acc, item) => {
30+
const name = item
31+
.replace('/index.js', '')
32+
.replace('src/directives/', 'Directives/')
33+
acc[name] = join(__dirname, item)
34+
return acc
35+
}, {}),
36+
37+
...globSync('src/functions/*/index.js').reduce((acc, item) => {
38+
const name = item
39+
.replace('/index.js', '')
40+
.replace('src/functions/', 'Functions/')
41+
acc[name] = join(__dirname, item)
42+
return acc
43+
}, {}),
44+
45+
...globSync('src/mixins/*/index.js').reduce((acc, item) => {
46+
const name = item
47+
.replace('/index.js', '')
48+
.replace('src/mixins/', 'Mixins/')
49+
acc[name] = join(__dirname, item)
50+
return acc
51+
}, {}),
52+
2053
index: resolve(__dirname, 'src/index.js'),
2154
}
2255

@@ -33,10 +66,6 @@ const vueDocsPlugin: Plugin = {
3366

3467
// Customizations for the vite config
3568
const overrides = defineConfig({
36-
build: {
37-
// Vite is run second so do not remove webpack files
38-
emptyOutDir: false,
39-
},
4069
plugins: [
4170
vueDocsPlugin,
4271
],

webpack.config.js

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
// config for the styleguide
2+
13
const webpackConfig = require('@nextcloud/webpack-vue-config')
24
const webpackRules = require('@nextcloud/webpack-vue-config/rules')
35

4-
const { globSync } = require('glob')
56
const md5 = require('md5')
67
const path = require('path')
78

89
const { DefinePlugin } = require('webpack')
910
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
10-
const nodeExternals = require('webpack-node-externals')
1111
const { loadTranslations } = require('./build/translations.js')
1212

1313
const buildMode = process.env.NODE_ENV
@@ -19,55 +19,7 @@ const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-
1919
const versionHash = md5(appVersion).slice(0, 7)
2020
const SCOPE_VERSION = JSON.stringify(versionHash)
2121

22-
console.info('This build version hash is', versionHash, '\n')
23-
24-
webpackConfig.entry = {
25-
...globSync('src/components/*/index.js').reduce((acc, item) => {
26-
const name = item
27-
.replace('/index.js', '')
28-
.replace('src/components/', 'Components/')
29-
acc[name] = path.join(__dirname, item)
30-
return acc
31-
}, {}),
32-
33-
...globSync('src/directives/*/index.js').reduce((acc, item) => {
34-
const name = item
35-
.replace('/index.js', '')
36-
.replace('src/directives/', 'Directives/')
37-
acc[name] = path.join(__dirname, item)
38-
return acc
39-
}, {}),
40-
41-
...globSync('src/functions/*/index.js').reduce((acc, item) => {
42-
const name = item
43-
.replace('/index.js', '')
44-
.replace('src/functions/', 'Functions/')
45-
acc[name] = path.join(__dirname, item)
46-
return acc
47-
}, {}),
48-
49-
...globSync('src/mixins/*/index.js').reduce((acc, item) => {
50-
const name = item
51-
.replace('/index.js', '')
52-
.replace('src/mixins/', 'Mixins/')
53-
acc[name] = path.join(__dirname, item)
54-
return acc
55-
}, {}),
56-
}
57-
5822
webpackConfig.devtool = isDev ? false : 'source-map'
59-
webpackConfig.output = {
60-
path: path.resolve(__dirname, './dist'),
61-
publicPath: '/dist/',
62-
filename: '[name].js',
63-
library: {
64-
type: 'umd',
65-
name: ['NextcloudVue', '[name]'],
66-
},
67-
umdNamedDefine: true,
68-
}
69-
70-
webpackConfig.externals = [nodeExternals()]
7123

7224
webpackRules.RULE_SCSS = {
7325
test: /\.scss$/,

0 commit comments

Comments
 (0)