-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrollup.config.js
160 lines (146 loc) · 4.27 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { camelCase } from "lodash"
import babel from "rollup-plugin-babel"
import commonjs from "rollup-plugin-commonjs"
import filesize from "rollup-plugin-filesize"
import json from "rollup-plugin-json"
import replace from "rollup-plugin-replace"
import vue from "rollup-plugin-vue"
import scss from 'rollup-plugin-scss'
import uglify from "rollup-plugin-uglify"
import typescript from "rollup-plugin-typescript2"
import externals from '@yelo/rollup-node-external'
import { minify } from "uglify-es"
import postcsscssvariables from "postcss-css-variables"
import atImport from "postcss-import"
import rollpost from "rollup-plugin-postcss"
const aliasTransform = require('./config/alias-transform').default
const scssImporter = require('./config/scss-importer').default
import pack from "./package.json"
import postcss from "postcss"
import autoprefixer from 'autoprefixer'
import postcssCustomMedia from "postcss-custom-media"
const fs = require('fs')
const projectName = 'fishtank-vue'
// compute globals from dependencies
const globals = pack.dependencies && Object.assign({}, ...Object.keys(pack.dependencies).map((key) => ({
[key]: camelCase(key)
})))
const aliasConfig = {
baseUrl: "",
paths: {
"@/*": [
"src/*"
]
},
rootDir: __dirname,
}
const builds = {
// (CommonJS). Used by bundlers e.g. Webpack & Browserify
cjs: {
entry: "src/index.ts",
dest: `dist/${projectName}.common.js`,
format: "cjs",
env: null
},
// (ES Modules). Used by bundlers that support ES Modules,
// e.g. Rollup & Webpack 2
esm: {
entry: "src/index.ts",
dest: `dist/${projectName}.esm.js`,
format: "es",
env : null
},
}
function genConfig(name, isProdVar, custProps) {
const opts = builds[name]
opts.env = isProdVar
const importOptions = {
filter:url=>url === '../styles/variables-custom-properties',
}
opts.dest =`dist/${projectName}.${name}${(custProps === 'true' ? ".vars":"")}${(isProdVar === null ? "":".min")}.js`
opts.compileCustomProperties = custProps === 'true' ? [ atImport(importOptions), autoprefixer, postcssCustomMedia] : [atImport(),postcsscssvariables,autoprefixer,postcssCustomMedia]
// Need to remove to stop generating empty placeholder external CSS files
// const scssOpts = {
// importer: scssImporter({ aliasConfig }),
// output: function (styles, styleNodes) {
// postcss([autoprefixer])
// .process(styles, {from:undefined})
// .then(results=>{
// fs.writeFileSync('dist/fishtank-vue.css', results)
// })
// },
// }
const config = {
input: opts.entry,
external: externals(),
plugins: [
aliasTransform(aliasConfig),
commonjs(),
vue(
{
needMap: false,
css: true,
style:{
rollpost:{
onImport:i=>{
console.log(i)
}
},
postcssPlugins:
opts.compileCustomProperties
,
postcssModulesOptions:{
generateScopedName: 'ft-[local]-[hash:base64:4]'
}
},
}
),
// scss(scssOpts),
typescript({
tsconfig: 'tsconfig.json',
experimentalDecorators: true,
module: 'es2015',
objectHashIgnoreUnknownHack:true,
clean:true
}),
babel({
exclude: "node_modules/**",
runtimeHelpers: true
}),
json(),
filesize()
].concat(opts.plugins || []),
output: {
exports: "named",
file: opts.dest,
format: opts.format,
name: opts.moduleName || projectName
},
}
if (opts.env) {
config.plugins.push(
replace({
"process.env.NODE_ENV": JSON.stringify(opts.env)
})
)
// minify on production targets
if (opts.env === "production") {
config.plugins.push(uglify({
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs:['console.warn']
}
}, minify))
}
}
Object.defineProperty(config, "_name", {
enumerable: false,
value: name
})
return config
}
const target = process.env.TARGET || "esm"
const isProd = process.env.PROD || null
const compileCustomProperties = process.env.compileCustomProperties || null
module.exports = genConfig(target, isProd, compileCustomProperties)