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