Skip to content

Commit 7ec652b

Browse files
committed
build: add tree shaking support
1 parent 50b1767 commit 7ec652b

File tree

4 files changed

+74
-66
lines changed

4 files changed

+74
-66
lines changed

.eslintrc.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ module.exports = {
44
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
55
sourceType: 'module', // Allows for the use of imports
66
extraFileExtensions: ['.vue'],
7-
ecmaFeatures: {
8-
jsx: true,
9-
},
107
},
118
extends: [
129
'eslint:recommended',
@@ -29,6 +26,18 @@ module.exports = {
2926
'vue/require-default-prop': 'off',
3027
},
3128
overrides: [
29+
{
30+
files: ['**/*.mjs'],
31+
env: {
32+
"env": {
33+
"browser": false,
34+
"node": true
35+
},
36+
"parserOptions": {
37+
"sourceType": "module"
38+
},
39+
},
40+
},
3241
{
3342
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
3443
env: {

packages/coreui-vue/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
},
2424
"license": "MIT",
2525
"author": "The CoreUI Team (https://github.com/orgs/coreui/people)",
26-
"main": "dist/index.js",
27-
"module": "dist/index.es.js",
28-
"types": "dist/index.d.ts",
26+
"main": "dist/cjs/index.js",
27+
"module": "dist/esm/index.js",
28+
"jsnext:main": "dist/esm/index.js",
29+
"types": "dist/esm/index.d.ts",
2930
"files": [
3031
"dist/",
3132
"src/"
3233
],
3334
"scripts": {
34-
"build": "rollup -c --bundleConfigAsCjs",
35+
"build": "npm-run-all clean build-*",
36+
"build-cjs": "rollup --environment ESM:false --config",
37+
"build-esm": "rollup --environment ESM:true --config",
38+
"clean": "cross-env-shell \"rm -rf dist\"",
3539
"test": "jest --coverage",
3640
"test:clear": "jest --clearCache",
3741
"test:update": "jest --coverage --updateSnapshot"
@@ -44,9 +48,10 @@
4448
"@types/jest": "^29.5.7",
4549
"@vue/test-utils": "^2.4.1",
4650
"@vue/vue3-jest": "29.2.6",
51+
"cross-env": "^7.0.3",
4752
"jest": "^29.7.0",
4853
"jest-environment-jsdom": "^29.7.0",
49-
"rollup": "^3.29.4",
54+
"rollup": "^4.2.0",
5055
"rollup-plugin-vue": "^6.0.0",
5156
"ts-jest": "^29.1.1",
5257
"typescript": "^5.2.2",

packages/coreui-vue/rollup.config.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/coreui-vue/rollup.config.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import commonjs from '@rollup/plugin-commonjs'
2+
import typescript from '@rollup/plugin-typescript'
3+
import resolve from '@rollup/plugin-node-resolve'
4+
import vue from 'rollup-plugin-vue'
5+
import { readFileSync } from 'node:fs'
6+
import { dirname } from 'node:path'
7+
8+
const pkg = JSON.parse(readFileSync(new URL('package.json', import.meta.url)))
9+
10+
const DIR_CJS = dirname(pkg.main)
11+
const DIR_ESM = dirname(pkg.module)
12+
const ESM = process.env.ESM === 'true'
13+
14+
const plugins = [
15+
resolve({
16+
dedupe: ['vue'],
17+
extensions: ['.ts', '.json', '.vue'],
18+
}),
19+
typescript({
20+
exclude: ['**/__tests__/**'],
21+
tsconfig: './tsconfig.json',
22+
compilerOptions: {
23+
declarationDir: ESM ? DIR_ESM : DIR_CJS,
24+
outDir: ESM ? DIR_ESM : DIR_CJS,
25+
},
26+
}),
27+
commonjs({
28+
include: ['../../node_modules/**'],
29+
}),
30+
ESM ? vue({ template: { optimizeSSR: true } }) : vue(),
31+
]
32+
33+
const external = ['@popperjs/core', 'vue']
34+
35+
const rollupConfig = {
36+
input: 'src/index.ts',
37+
output: {
38+
dir: ESM ? DIR_ESM : DIR_CJS,
39+
format: ESM ? 'esm' : 'cjs',
40+
exports: 'named',
41+
preserveModules: true,
42+
preserveModulesRoot: 'src',
43+
sourcemap: true,
44+
sourcemapPathTransform: (relativeSourcePath) => {
45+
return relativeSourcePath.replace('../../node_modules/', '../').replace('../src/', 'src/')
46+
},
47+
},
48+
external,
49+
plugins,
50+
}
51+
52+
export default rollupConfig

0 commit comments

Comments
 (0)