Skip to content

Commit 8a3037a

Browse files
committed
feat: Migrate module build to vite
* Webpack emitted invalid ES module code, as it still contained `require` calls which are undefined on ES modules * Build time is much shorter * Built assets are much smaller (570 kB vs 930 kB) * Remove unneeded import Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 7d1a455 commit 8a3037a

13 files changed

Lines changed: 123 additions & 42 deletions

File tree

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ module.exports = {
1414
plugins: [
1515
'cypress',
1616
],
17+
parserOptions: {
18+
babelOptions: {
19+
plugins: [
20+
'@babel/plugin-syntax-import-assertions',
21+
],
22+
},
23+
},
1724
}

build/usernameToColor-export.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const snapshot = require('./../src/functions/usernameToColor/__snapshots__/usernameToColor.spec.js.snap')
22
const result = {}
33
Object.keys(snapshot).map((key) => {
4-
const uid = key.replace('usernameToColor ', '').replace(' has the proper color 1', '')
5-
result[uid] = JSON.parse(snapshot[key])
4+
const uid = key.replace('usernameToColor ', '').replace(' has the proper color 1', '')
5+
result[uid] = JSON.parse(snapshot[key])
66
})
77
console.log(JSON.stringify(result))

cypress.config.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { defineConfig } from 'cypress'
2-
import { DefinePlugin } from 'webpack'
3-
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin'
2+
import webpack from 'webpack'
3+
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin.js'
44
import path from 'path'
55
import webpackConfig from '@nextcloud/webpack-vue-config'
6-
import webpackRules from '@nextcloud/webpack-vue-config/rules'
6+
import webpackRules from '@nextcloud/webpack-vue-config/rules.js'
77

8-
import { loadTranslations } from './resources/translations'
8+
import { loadTranslations } from './build/translations.js'
99

10-
const SCOPE_VERSION = Date.now()
11-
webpackRules.RULE_SCSS.use.push({
10+
const SCOPE_VERSION = Date.now();
11+
12+
(webpackRules.RULE_SCSS.use as webpack.RuleSetUse[]).push({
1213
loader: 'sass-loader',
1314
options: {
1415
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
@@ -72,7 +73,7 @@ export default defineConfig({
7273
bundler: 'webpack',
7374
webpackConfig: async () => {
7475
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))
75-
webpackConfig.plugins.push(new DefinePlugin({
76+
webpackConfig.plugins.push(new webpack.DefinePlugin({
7677
PRODUCTION: false,
7778
SCOPE_VERSION,
7879
TRANSLATIONS: JSON.stringify(translations),

cypress/visual/NcAppSidebar/NcAppSidebar-compact.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import BuildAppSidebarTest from './NcAppSidebarMixin'
22+
import BuildAppSidebarTest from './NcAppSidebarMixin.js'
2323

2424
BuildAppSidebarTest(true)

cypress/visual/NcAppSidebar/NcAppSidebar.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import BuildAppSidebarTest from './NcAppSidebarMixin'
22+
import BuildAppSidebarTest from './NcAppSidebarMixin.js'
2323

2424
BuildAppSidebarTest(false)

package-lock.json

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

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"scripts": {
1616
"dev": "webpack --node-env development --progress",
1717
"watch": "webpack --node-env development --progress --watch",
18-
"watch:module": "LIBRARY_TARGET=module webpack --node-env development --progress --watch",
18+
"watch:module": "vite build --mode development --watch",
1919
"build": "webpack --node-env production --progress && npm run build:module",
20-
"build:module": "LIBRARY_TARGET=module webpack --node-env production --progress",
20+
"build:module": "vite --mode production build",
2121
"l10n:extract": "node build/extract-l10n.js",
2222
"lint": "eslint --ext .js,.vue src",
2323
"lint:fix": "eslint --ext .js,.vue src --fix",
@@ -31,8 +31,14 @@
3131
"cypress:gui": "TZ=UTC cypress open --component",
3232
"cypress:update-snapshots": "TZ=UTC cypress run --component --spec cypress/visual/**/*.cy.js --env type=base --config screenshotsFolder=cypress/snapshots/base"
3333
},
34-
"main": "dist/ncvuecomponents.js",
35-
"module": "dist/index.module.js",
34+
"main": "dist/index.js",
35+
"exports": {
36+
".": {
37+
"import": "./dist/index.mjs",
38+
"require": "./dist/index.js"
39+
},
40+
"./dist/": "./dist/"
41+
},
3642
"files": [
3743
"CHANGELOG.md",
3844
"LICENSE",
@@ -87,6 +93,7 @@
8793
"npm": "^9.0.0"
8894
},
8995
"devDependencies": {
96+
"@babel/plugin-syntax-import-assertions": "^7.22.5",
9097
"@babel/preset-typescript": "^7.22.5",
9198
"@cypress/vue2": "^2.0.1",
9299
"@fontsource/roboto": "^5.0.0",
@@ -96,6 +103,7 @@
96103
"@nextcloud/eslint-config": "^8.3.0-beta.0",
97104
"@nextcloud/stylelint-config": "^2.3.1",
98105
"@nextcloud/webpack-vue-config": "github:nextcloud/webpack-vue-config#master",
106+
"@susnux/nextcloud-vite-config": "^1.0.0-beta.13",
99107
"@vue/test-utils": "^1.3.0",
100108
"@vue/tsconfig": "^0.4.0",
101109
"@vue/vue2-jest": "^29.0.0",
@@ -117,9 +125,11 @@
117125
"ts-node": "^10.9.1",
118126
"typescript": "^5.0.4",
119127
"url-loader": "^4.1.1",
128+
"vite": "^4.3.9",
120129
"vue-eslint-parser": "^9.0.3",
121130
"vue-styleguidist": "~4.72.0",
122131
"vue-template-compiler": "^2.7.14",
132+
"webpack": "^5.88.1",
123133
"webpack-merge": "^5.9.0",
124134
"webpack-node-externals": "^3.0.0"
125135
},

src/components/NcDatetimePicker/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$cell_height: 32px;
22

3-
@import '~vue2-datepicker/scss/index';
3+
@import 'vue2-datepicker/scss/index';
44

55
.mx-datepicker[data-v-#{$scope_version}] {
66
user-select: none;

src/components/NcEmojiPicker/NcEmojiPicker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export default {
295295
</script>
296296
297297
<style lang="scss">
298-
@import '~emoji-mart-vue-fast/css/emoji-mart.css';
298+
@import 'emoji-mart-vue-fast/css/emoji-mart.css';
299299
300300
.emoji-mart {
301301
background-color: var(--color-main-background) !important;

0 commit comments

Comments
 (0)