@@ -4,11 +4,10 @@ import path from "path";
44import vue from "rollup-plugin-vue" ;
55import alias from "@rollup/plugin-alias" ;
66import commonjs from "@rollup/plugin-commonjs" ;
7+ import resolve from "@rollup/plugin-node-resolve" ;
78import 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" ;
1010import { terser } from "rollup-plugin-terser" ;
11- import postcssLogical from "postcss-logical" ;
1211import minimist from "minimist" ;
1312
1413// Get browserslist config and remove ie from es build targets
@@ -18,6 +17,11 @@ const esbrowserslist = fs
1817 . split ( "\n" )
1918 . filter ( ( entry ) => entry && entry . substring ( 0 , 2 ) !== "ie" ) ;
2019
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+
2125const argv = minimist ( process . argv . slice ( 2 ) ) ;
2226
2327const projectRoot = path . resolve ( __dirname , ".." ) ;
@@ -27,25 +31,33 @@ const baseConfig = {
2731 plugins : {
2832 preVue : [
2933 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+ ] ,
3440 } ) ,
3541 ] ,
3642 replace : {
3743 "process.env.NODE_ENV" : JSON . stringify ( "production" ) ,
38- "process.env.ES_BUILD" : JSON . stringify ( "false" ) ,
3944 } ,
4045 vue : {
4146 css : true ,
4247 template : {
4348 isProduction : true ,
4449 } ,
4550 } ,
51+ postVue : [
52+ resolve ( {
53+ extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
54+ } ) ,
55+ commonjs ( ) ,
56+ ] ,
4657 babel : {
4758 exclude : "node_modules/**" ,
4859 extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
60+ babelHelpers : "bundled" ,
4961 } ,
5062 } ,
5163} ;
@@ -71,31 +83,30 @@ const buildFormats = [];
7183if ( ! argv . format || argv . format === "es" ) {
7284 const esConfig = {
7385 ...baseConfig ,
86+ input : "src/entry.esm.js" ,
7487 external,
7588 output : {
76- file : "dist/esm.js" ,
77- format : "es " ,
89+ file : "dist/esm.js" , // custom
90+ format : "esm " ,
7891 exports : "named" ,
7992 } ,
8093 plugins : [
81- replace ( {
82- ...baseConfig . plugins . replace ,
83- "process.env.ES_BUILD" : JSON . stringify ( "true" ) ,
84- } ) ,
94+ replace ( baseConfig . plugins . replace ) ,
8595 ...baseConfig . plugins . preVue ,
8696 vue ( baseConfig . plugins . vue ) ,
97+ ...baseConfig . plugins . postVue ,
8798 babel ( {
8899 ...baseConfig . plugins . babel ,
89100 presets : [
90101 [
91102 "@babel/preset-env" ,
92103 {
104+ ...babelPresetEnvConfig ,
93105 targets : esbrowserslist ,
94106 } ,
95107 ] ,
96108 ] ,
97109 } ) ,
98- commonjs ( ) ,
99110 ] ,
100111 } ;
101112 buildFormats . push ( esConfig ) ;
@@ -107,10 +118,10 @@ if (!argv.format || argv.format === "cjs") {
107118 external,
108119 output : {
109120 compact : true ,
110- file : "dist/ssr.js" ,
121+ file : "dist/ssr.js" , // custom
111122 format : "cjs" ,
112123 name : "VueNotion" ,
113- exports : "named " ,
124+ exports : "auto " ,
114125 globals,
115126 } ,
116127 plugins : [
@@ -123,8 +134,8 @@ if (!argv.format || argv.format === "cjs") {
123134 optimizeSSR : true ,
124135 } ,
125136 } ) ,
137+ ...baseConfig . plugins . postVue ,
126138 babel ( baseConfig . plugins . babel ) ,
127- commonjs ( ) ,
128139 ] ,
129140 } ;
130141 buildFormats . push ( umdConfig ) ;
@@ -136,18 +147,18 @@ if (!argv.format || argv.format === "iife") {
136147 external,
137148 output : {
138149 compact : true ,
139- file : "dist/min.js" ,
150+ file : "dist/min.js" , // custom
140151 format : "iife" ,
141152 name : "VueNotion" ,
142- exports : "named " ,
153+ exports : "auto " ,
143154 globals,
144155 } ,
145156 plugins : [
146157 replace ( baseConfig . plugins . replace ) ,
147158 ...baseConfig . plugins . preVue ,
148159 vue ( baseConfig . plugins . vue ) ,
160+ ...baseConfig . plugins . postVue ,
149161 babel ( baseConfig . plugins . babel ) ,
150- commonjs ( ) ,
151162 terser ( {
152163 output : {
153164 ecma : 5 ,
@@ -158,28 +169,5 @@ if (!argv.format || argv.format === "iife") {
158169 buildFormats . push ( unpkgConfig ) ;
159170}
160171
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-
179172// 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