Skip to content

Commit 24a45a5

Browse files
committed
feat: add rollup esm build
1 parent c593ad9 commit 24a45a5

File tree

3 files changed

+158
-2
lines changed

3 files changed

+158
-2
lines changed

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"version": "3.0.0-bridge-alpha.1",
55
"license": "MIT",
66
"main": "dist/coreui-vue.common.js",
7-
"module": "dist/coreui-vue.esm.js",
87
"files": [
98
"src",
109
"dist/*.js"
@@ -49,6 +48,7 @@
4948
"serve": "vue-cli-service serve",
5049
"build": "npm-run-all --parallel build:custom build:default",
5150
"build:default": "vue-cli-service build --target lib --name coreui-vue ./src/index.js",
51+
"build:es": "rollup -c --environment TARGET:esm",
5252
"build:custom": "npm-run-all createCustom buildCustom deleteCustom",
5353
"createCustom": "node build/createCustomStylesLibrary.js",
5454
"buildCustom": "vue-cli-service build --target lib --name custom ./tmp/index.js",
@@ -90,8 +90,22 @@
9090
"eslint-plugin-vue": "^5.0.0-beta.5",
9191
"growl": "^1.10.5",
9292
"https-proxy-agent": "^2.2.1",
93+
"lodash": "^4.17.11",
9394
"node-sass": "^4.11.0",
95+
"node-sass-magic-importer": "^5.3.2",
96+
"rollup": "^1.14.3",
97+
"rollup-plugin-babel": "^4.3.2",
98+
"rollup-plugin-commonjs": "^9.3.2",
99+
"rollup-plugin-filesize": "^5.0.1",
100+
"rollup-plugin-json": "^3.1.0",
101+
"rollup-plugin-license": "^0.7.0",
102+
"rollup-plugin-node-resolve": "^3.4.0",
103+
"rollup-plugin-postcss": "^2.0.3",
104+
"rollup-plugin-replace": "^2.1.0",
105+
"rollup-plugin-uglify": "^6.0.0",
106+
"rollup-plugin-vue": "^4.3.2",
94107
"sass-loader": "^7.1.0",
108+
"uglify-es": "^3.3.9",
95109
"vue-jest": "^3.0.1",
96110
"vue-router": "^3.0.2",
97111
"vue-template-compiler": "^2.6.6"

rollup.config.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { camelCase } from "lodash";
2+
import path from "path";
3+
import babel from "rollup-plugin-babel";
4+
import commonjs from "rollup-plugin-commonjs";
5+
import filesize from "rollup-plugin-filesize";
6+
import json from "rollup-plugin-json";
7+
import license from "rollup-plugin-license";
8+
import postcss from 'rollup-plugin-postcss'
9+
import resolve from "rollup-plugin-node-resolve";
10+
import replace from "rollup-plugin-replace";
11+
import magicImporter from 'node-sass-magic-importer';
12+
13+
import { uglify } from "rollup-plugin-uglify";
14+
import vue from "rollup-plugin-vue";
15+
import { minify } from "uglify-es";
16+
17+
import pack from "./package.json";
18+
19+
const projectName = "coreui-vue";
20+
21+
// compute globals from dependencies
22+
const globals = pack.dependencies && Object.assign({}, ...Object.keys(pack.dependencies).map((key) => ({
23+
[key]: camelCase(key)
24+
})));
25+
26+
const builds = {
27+
// (CommonJS). Used by bundlers e.g. Webpack & Browserify
28+
cjs: {
29+
entry: "src/index.js",
30+
dest: `dist/${projectName}.common.js`,
31+
format: "cjs"
32+
},
33+
// (ES Modules). Used by bundlers that support ES Modules,
34+
// e.g. Rollup & Webpack 2
35+
esm: {
36+
entry: "src/index.js",
37+
dest: `dist/${projectName}.esm.js`,
38+
format: "esm"
39+
},
40+
// build (Browser)
41+
"umd-dev": {
42+
entry: "src/index.umd.js",
43+
dest: `dist/${projectName}.js`,
44+
format: "umd",
45+
env: "development"
46+
},
47+
// production build (Browser)
48+
"umd-prod": {
49+
entry: "src/index.umd.js",
50+
dest: `dist/${projectName}.min.js`,
51+
format: "umd",
52+
env: "production"
53+
}
54+
};
55+
56+
function genConfig(name) {
57+
const opts = builds[name];
58+
const config = {
59+
input: opts.entry,
60+
// external: (id) => pack.dependencies && pack.dependencies[id], // exclude dependencies from build
61+
// external: ['@coreui/icons', '@coreui/icons/vue'],
62+
// preserveModules: true,
63+
treeshake: {
64+
// moduleSideEffects: false,
65+
pureExternalModules: true,
66+
propertyReadSideEffects: false
67+
},
68+
plugins: [
69+
resolve({
70+
// module: true,
71+
// browser: true,
72+
// jsnext: true,
73+
// preferBuiltins: false,
74+
extensions: [".js", ".json", ".vue"]
75+
}),
76+
commonjs(),
77+
postcss(),
78+
vue({
79+
compileTemplate: true,
80+
css: false,
81+
style: {
82+
preprocessOptions: {
83+
scss: {
84+
importer: magicImporter(),
85+
},
86+
},
87+
}
88+
}),
89+
json(),
90+
babel({
91+
exclude: "node_modules/**",
92+
runtimeHelpers: true,
93+
presets: [
94+
["@vue/app", { modules: false }]
95+
]
96+
}),
97+
filesize()
98+
].concat(opts.plugins || []),
99+
output: {
100+
exports: "named",
101+
file: opts.dest,
102+
// dir: 'dist/es',
103+
format: opts.format,
104+
// define globals in window from external dependencies
105+
globals,
106+
name: opts.moduleName || projectName
107+
}
108+
};
109+
110+
if (opts.env) {
111+
config.plugins.push(
112+
replace({
113+
"process.env.NODE_ENV": JSON.stringify(opts.env)
114+
})
115+
);
116+
117+
// minify on production targets
118+
// if (opts.env === "production") {
119+
// config.plugins.push(uglify({}, minify));
120+
// }
121+
}
122+
123+
// output a license to builds
124+
config.plugins.push(
125+
license({
126+
sourceMap: true,
127+
banner: {
128+
file: path.resolve("LICENSE.md")
129+
}
130+
})
131+
);
132+
133+
Object.defineProperty(config, "_name", {
134+
enumerable: false,
135+
value: name
136+
});
137+
138+
return config;
139+
}
140+
141+
const target = process.env.TARGET || "umd-prod";
142+
module.exports = genConfig(target);

src/components/Dropdown/CDropdown.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import CLink from '../Link/CLink'
33
import Popper from 'popper.js'
44
import { mixin as clickaway } from 'vue-clickaway2'
5-
import { deepObjectsMerge } from '@coreui/coreui/dist/js/coreui-utilities'
5+
import deepObjectsMerge from '@coreui/coreui/js/src/utilities/deep-objects-merge'
66
77
export default {
88
name: 'CDropdown',

0 commit comments

Comments
 (0)