@@ -4,11 +4,10 @@ import path from "path";
4
4
import vue from "rollup-plugin-vue" ;
5
5
import alias from "@rollup/plugin-alias" ;
6
6
import commonjs from "@rollup/plugin-commonjs" ;
7
+ import resolve from "@rollup/plugin-node-resolve" ;
7
8
import replace from "@rollup/plugin-replace" ;
8
- import babel from "rollup-plugin-babel" ;
9
- import postcss from "rollup-plugin-postcss" ;
9
+ import babel from "@rollup/plugin-babel" ;
10
10
import { terser } from "rollup-plugin-terser" ;
11
- import postcssLogical from "postcss-logical" ;
12
11
import minimist from "minimist" ;
13
12
14
13
// Get browserslist config and remove ie from es build targets
@@ -18,6 +17,11 @@ const esbrowserslist = fs
18
17
. split ( "\n" )
19
18
. filter ( ( entry ) => entry && entry . substring ( 0 , 2 ) !== "ie" ) ;
20
19
20
+ // Extract babel preset-env config, to combine with esbrowserslist
21
+ const babelPresetEnvConfig = require ( "../babel.config" ) . presets . filter (
22
+ ( entry ) => entry [ 0 ] === "@babel/preset-env"
23
+ ) [ 0 ] [ 1 ] ;
24
+
21
25
const argv = minimist ( process . argv . slice ( 2 ) ) ;
22
26
23
27
const projectRoot = path . resolve ( __dirname , ".." ) ;
@@ -27,25 +31,33 @@ const baseConfig = {
27
31
plugins : {
28
32
preVue : [
29
33
alias ( {
30
- resolve : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
31
- entries : {
32
- "@" : path . resolve ( projectRoot , "src" ) ,
33
- } ,
34
+ entries : [
35
+ {
36
+ find : "@" ,
37
+ replacement : `${ path . resolve ( projectRoot , "src" ) } ` ,
38
+ } ,
39
+ ] ,
34
40
} ) ,
35
41
] ,
36
42
replace : {
37
43
"process.env.NODE_ENV" : JSON . stringify ( "production" ) ,
38
- "process.env.ES_BUILD" : JSON . stringify ( "false" ) ,
39
44
} ,
40
45
vue : {
41
46
css : true ,
42
47
template : {
43
48
isProduction : true ,
44
49
} ,
45
50
} ,
51
+ postVue : [
52
+ resolve ( {
53
+ extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
54
+ } ) ,
55
+ commonjs ( ) ,
56
+ ] ,
46
57
babel : {
47
58
exclude : "node_modules/**" ,
48
59
extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
60
+ babelHelpers : "bundled" ,
49
61
} ,
50
62
} ,
51
63
} ;
@@ -71,31 +83,30 @@ const buildFormats = [];
71
83
if ( ! argv . format || argv . format === "es" ) {
72
84
const esConfig = {
73
85
...baseConfig ,
86
+ input : "src/entry.esm.js" ,
74
87
external,
75
88
output : {
76
- file : "dist/esm.js" ,
77
- format : "es " ,
89
+ file : "dist/esm.js" , // custom
90
+ format : "esm " ,
78
91
exports : "named" ,
79
92
} ,
80
93
plugins : [
81
- replace ( {
82
- ...baseConfig . plugins . replace ,
83
- "process.env.ES_BUILD" : JSON . stringify ( "true" ) ,
84
- } ) ,
94
+ replace ( baseConfig . plugins . replace ) ,
85
95
...baseConfig . plugins . preVue ,
86
96
vue ( baseConfig . plugins . vue ) ,
97
+ ...baseConfig . plugins . postVue ,
87
98
babel ( {
88
99
...baseConfig . plugins . babel ,
89
100
presets : [
90
101
[
91
102
"@babel/preset-env" ,
92
103
{
104
+ ...babelPresetEnvConfig ,
93
105
targets : esbrowserslist ,
94
106
} ,
95
107
] ,
96
108
] ,
97
109
} ) ,
98
- commonjs ( ) ,
99
110
] ,
100
111
} ;
101
112
buildFormats . push ( esConfig ) ;
@@ -107,10 +118,10 @@ if (!argv.format || argv.format === "cjs") {
107
118
external,
108
119
output : {
109
120
compact : true ,
110
- file : "dist/ssr.js" ,
121
+ file : "dist/ssr.js" , // custom
111
122
format : "cjs" ,
112
123
name : "VueNotion" ,
113
- exports : "named " ,
124
+ exports : "auto " ,
114
125
globals,
115
126
} ,
116
127
plugins : [
@@ -123,8 +134,8 @@ if (!argv.format || argv.format === "cjs") {
123
134
optimizeSSR : true ,
124
135
} ,
125
136
} ) ,
137
+ ...baseConfig . plugins . postVue ,
126
138
babel ( baseConfig . plugins . babel ) ,
127
- commonjs ( ) ,
128
139
] ,
129
140
} ;
130
141
buildFormats . push ( umdConfig ) ;
@@ -136,18 +147,18 @@ if (!argv.format || argv.format === "iife") {
136
147
external,
137
148
output : {
138
149
compact : true ,
139
- file : "dist/min.js" ,
150
+ file : "dist/min.js" , // custom
140
151
format : "iife" ,
141
152
name : "VueNotion" ,
142
- exports : "named " ,
153
+ exports : "auto " ,
143
154
globals,
144
155
} ,
145
156
plugins : [
146
157
replace ( baseConfig . plugins . replace ) ,
147
158
...baseConfig . plugins . preVue ,
148
159
vue ( baseConfig . plugins . vue ) ,
160
+ ...baseConfig . plugins . postVue ,
149
161
babel ( baseConfig . plugins . babel ) ,
150
- commonjs ( ) ,
151
162
terser ( {
152
163
output : {
153
164
ecma : 5 ,
@@ -158,28 +169,5 @@ if (!argv.format || argv.format === "iife") {
158
169
buildFormats . push ( unpkgConfig ) ;
159
170
}
160
171
161
- if ( ! argv . format || argv . format === "postcss" ) {
162
- const postCssConfig = {
163
- input : "build/postcss.js" ,
164
- output : {
165
- format : "es" ,
166
- file : "dist/styles.ignore" ,
167
- } ,
168
- plugins : [
169
- postcss ( {
170
- extract : true ,
171
- minimize : true ,
172
- plugins : [ postcssLogical ( ) ] ,
173
- } ) ,
174
- ] ,
175
- } ;
176
- buildFormats . push ( postCssConfig ) ;
177
- }
178
-
179
172
// Export config
180
- export default ( commandLineArgs ) => {
181
- // Exporting a method enables command line args override
182
- // https://rollupjs.org/guide/en/#configuration-files
183
- delete commandLineArgs . format ;
184
- return buildFormats ;
185
- } ;
173
+ export default buildFormats ;
0 commit comments