@@ -4,10 +4,11 @@ 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" ;
87import 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" ;
1010import { terser } from "rollup-plugin-terser" ;
11+ import postcssLogical from "postcss-logical" ;
1112import minimist from "minimist" ;
1213
1314// Get browserslist config and remove ie from es build targets
@@ -17,11 +18,6 @@ const esbrowserslist = fs
1718 . split ( "\n" )
1819 . filter ( ( entry ) => entry && entry . substring ( 0 , 2 ) !== "ie" ) ;
1920
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-
2521const argv = minimist ( process . argv . slice ( 2 ) ) ;
2622
2723const projectRoot = path . resolve ( __dirname , ".." ) ;
@@ -31,33 +27,25 @@ const baseConfig = {
3127 plugins : {
3228 preVue : [
3329 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+ } ,
4034 } ) ,
4135 ] ,
4236 replace : {
4337 "process.env.NODE_ENV" : JSON . stringify ( "production" ) ,
38+ "process.env.ES_BUILD" : JSON . stringify ( "false" ) ,
4439 } ,
4540 vue : {
4641 css : true ,
4742 template : {
4843 isProduction : true ,
4944 } ,
5045 } ,
51- postVue : [
52- resolve ( {
53- extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
54- } ) ,
55- commonjs ( ) ,
56- ] ,
5746 babel : {
5847 exclude : "node_modules/**" ,
5948 extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" , ".vue" ] ,
60- babelHelpers : "bundled" ,
6149 } ,
6250 } ,
6351} ;
@@ -83,30 +71,31 @@ const buildFormats = [];
8371if ( ! argv . format || argv . format === "es" ) {
8472 const esConfig = {
8573 ...baseConfig ,
86- input : "src/entry.esm.js" ,
8774 external,
8875 output : {
89- file : "dist/esm.js" , // custom
90- format : "esm " ,
76+ file : "dist/esm.js" ,
77+ format : "es " ,
9178 exports : "named" ,
9279 } ,
9380 plugins : [
94- replace ( baseConfig . plugins . replace ) ,
81+ replace ( {
82+ ...baseConfig . plugins . replace ,
83+ "process.env.ES_BUILD" : JSON . stringify ( "true" ) ,
84+ } ) ,
9585 ...baseConfig . plugins . preVue ,
9686 vue ( baseConfig . plugins . vue ) ,
97- ...baseConfig . plugins . postVue ,
9887 babel ( {
9988 ...baseConfig . plugins . babel ,
10089 presets : [
10190 [
10291 "@babel/preset-env" ,
10392 {
104- ...babelPresetEnvConfig ,
10593 targets : esbrowserslist ,
10694 } ,
10795 ] ,
10896 ] ,
10997 } ) ,
98+ commonjs ( ) ,
11099 ] ,
111100 } ;
112101 buildFormats . push ( esConfig ) ;
@@ -118,10 +107,10 @@ if (!argv.format || argv.format === "cjs") {
118107 external,
119108 output : {
120109 compact : true ,
121- file : "dist/ssr.js" , // custom
110+ file : "dist/ssr.js" ,
122111 format : "cjs" ,
123112 name : "VueNotion" ,
124- exports : "auto " ,
113+ exports : "named " ,
125114 globals,
126115 } ,
127116 plugins : [
@@ -134,8 +123,8 @@ if (!argv.format || argv.format === "cjs") {
134123 optimizeSSR : true ,
135124 } ,
136125 } ) ,
137- ...baseConfig . plugins . postVue ,
138126 babel ( baseConfig . plugins . babel ) ,
127+ commonjs ( ) ,
139128 ] ,
140129 } ;
141130 buildFormats . push ( umdConfig ) ;
@@ -147,18 +136,18 @@ if (!argv.format || argv.format === "iife") {
147136 external,
148137 output : {
149138 compact : true ,
150- file : "dist/min.js" , // custom
139+ file : "dist/min.js" ,
151140 format : "iife" ,
152141 name : "VueNotion" ,
153- exports : "auto " ,
142+ exports : "named " ,
154143 globals,
155144 } ,
156145 plugins : [
157146 replace ( baseConfig . plugins . replace ) ,
158147 ...baseConfig . plugins . preVue ,
159148 vue ( baseConfig . plugins . vue ) ,
160- ...baseConfig . plugins . postVue ,
161149 babel ( baseConfig . plugins . babel ) ,
150+ commonjs ( ) ,
162151 terser ( {
163152 output : {
164153 ecma : 5 ,
@@ -169,5 +158,28 @@ if (!argv.format || argv.format === "iife") {
169158 buildFormats . push ( unpkgConfig ) ;
170159}
171160
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+
172179// 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