1
+ // rollup.config.js
2
+ import fs from 'fs' ;
3
+ import path from 'path' ;
4
+ import vue from 'rollup-plugin-vue' ;
5
+ import alias from '@rollup/plugin-alias' ;
6
+ import commonjs from '@rollup/plugin-commonjs' ;
7
+ import resolve from '@rollup/plugin-node-resolve' ;
8
+ import replace from '@rollup/plugin-replace' ;
9
+ import babel from '@rollup/plugin-babel' ;
10
+ import scss from "rollup-plugin-scss" ;
11
+
12
+
13
+ import { terser } from 'rollup-plugin-terser' ;
14
+ import minimist from 'minimist' ;
15
+
16
+ // Get browserslist config and remove ie from es build targets
17
+ const esbrowserslist = fs . readFileSync ( './.browserslistrc' )
18
+ . toString ( )
19
+ . split ( '\n' )
20
+ . filter ( ( entry ) => entry && entry . substring ( 0 , 2 ) !== 'ie' ) ;
21
+
22
+ // Extract babel preset-env config, to combine with esbrowserslist
23
+ const babelPresetEnvConfig = require ( '../babel.config' )
24
+ . presets . filter ( ( entry ) => entry [ 0 ] === '@babel/preset-env' ) [ 0 ] [ 1 ] ;
25
+
26
+ const argv = minimist ( process . argv . slice ( 2 ) ) ;
27
+
28
+ const projectRoot = path . resolve ( __dirname , '..' ) ;
29
+
30
+ const baseConfig = {
31
+ input : 'src/entry.js' ,
32
+ plugins : {
33
+ preVue : [
34
+ alias ( {
35
+ entries : [
36
+ {
37
+ find : '@' ,
38
+ replacement : `${ path . resolve ( projectRoot , 'src' ) } ` ,
39
+ } ,
40
+ ] ,
41
+ } ) ,
42
+ ] ,
43
+ replace : {
44
+ 'process.env.NODE_ENV' : JSON . stringify ( 'production' ) ,
45
+ } ,
46
+ vue : {
47
+ css : false ,
48
+ template : {
49
+ isProduction : true ,
50
+ } ,
51
+ } ,
52
+ postVue : [
53
+ resolve ( {
54
+ extensions : [ '.js' , '.jsx' , '.ts' , '.tsx' , '.vue' ] ,
55
+ } ) ,
56
+ commonjs ( ) ,
57
+ ] ,
58
+ babel : {
59
+ exclude : 'node_modules/**' ,
60
+ extensions : [ '.js' , '.jsx' , '.ts' , '.tsx' , '.vue' ] ,
61
+ babelHelpers : 'bundled' ,
62
+ } ,
63
+ } ,
64
+ } ;
65
+
66
+ // ESM/UMD/IIFE shared settings: externals
67
+ // Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
68
+ const external = [
69
+ // list external dependencies, exactly the way it is written in the import statement.
70
+ // eg. 'jquery'
71
+ 'vue' ,
72
+ ] ;
73
+
74
+ // UMD/IIFE shared settings: output.globals
75
+ // Refer to https://rollupjs.org/guide/en#output-globals for details
76
+ const globals = {
77
+ // Provide global variable names to replace your external imports
78
+ // eg. jquery: '$'
79
+ vue : 'Vue' ,
80
+ } ;
81
+
82
+ // Customize configs for individual targets
83
+ const buildFormats = [ ] ;
84
+
85
+ const cssConfig = {
86
+ input : 'src/styles.js' ,
87
+ plugins : [
88
+ scss ( {
89
+ output : 'dist/VueLightboxAdvanced.css' ,
90
+ outputStyle : "compressed" ,
91
+ } )
92
+ ] ,
93
+ } ;
94
+
95
+ buildFormats . push ( cssConfig ) ;
96
+
97
+ if ( ! argv . format || argv . format === 'es' ) {
98
+ const esConfig = {
99
+ ...baseConfig ,
100
+ input : 'src/entry.esm.js' ,
101
+ external,
102
+ output : {
103
+ file : 'dist/VueLightboxAdvanced.esm.js' ,
104
+ format : 'esm' ,
105
+ exports : 'named' ,
106
+ } ,
107
+ plugins : [
108
+ replace ( baseConfig . plugins . replace ) ,
109
+ ...baseConfig . plugins . preVue ,
110
+ vue ( baseConfig . plugins . vue ) ,
111
+ ...baseConfig . plugins . postVue ,
112
+ babel ( {
113
+ ...baseConfig . plugins . babel ,
114
+ presets : [
115
+ [
116
+ '@babel/preset-env' ,
117
+ {
118
+ ...babelPresetEnvConfig ,
119
+ targets : esbrowserslist ,
120
+ } ,
121
+ ] ,
122
+ ] ,
123
+ } ) ,
124
+ ] ,
125
+ } ;
126
+ buildFormats . push ( esConfig ) ;
127
+ }
128
+
129
+ if ( ! argv . format || argv . format === 'cjs' ) {
130
+ const umdConfig = {
131
+ ...baseConfig ,
132
+ external,
133
+ output : {
134
+ compact : true ,
135
+ file : 'dist/VueLightboxAdvanced.ssr.js' ,
136
+ format : 'cjs' ,
137
+ name : 'VueLightboxAdvanced' ,
138
+ exports : 'auto' ,
139
+ globals,
140
+ } ,
141
+ plugins : [
142
+ replace ( baseConfig . plugins . replace ) ,
143
+ ...baseConfig . plugins . preVue ,
144
+ vue ( {
145
+ ...baseConfig . plugins . vue ,
146
+ template : {
147
+ ...baseConfig . plugins . vue . template ,
148
+ optimizeSSR : true ,
149
+ } ,
150
+ } ) ,
151
+ ...baseConfig . plugins . postVue ,
152
+ babel ( baseConfig . plugins . babel ) ,
153
+ ] ,
154
+ } ;
155
+ buildFormats . push ( umdConfig ) ;
156
+ }
157
+
158
+ if ( ! argv . format || argv . format === 'iife' ) {
159
+ const unpkgConfig = {
160
+ ...baseConfig ,
161
+ external,
162
+ output : {
163
+ compact : true ,
164
+ file : 'dist/VueLightboxAdvanced.min.js' ,
165
+ format : 'iife' ,
166
+ name : 'VueLightboxAdvanced' ,
167
+ exports : 'auto' ,
168
+ globals,
169
+ } ,
170
+ plugins : [
171
+ replace ( baseConfig . plugins . replace ) ,
172
+ ...baseConfig . plugins . preVue ,
173
+ vue ( baseConfig . plugins . vue ) ,
174
+ ...baseConfig . plugins . postVue ,
175
+ babel ( baseConfig . plugins . babel ) ,
176
+ terser ( {
177
+ output : {
178
+ ecma : 5 ,
179
+ } ,
180
+ } ) ,
181
+ ] ,
182
+ } ;
183
+ buildFormats . push ( unpkgConfig ) ;
184
+ }
185
+
186
+ // Export config
187
+ export default buildFormats ;
0 commit comments