forked from bloombergindustry/fishtank-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
130 lines (114 loc) · 2.97 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
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"
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'
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"
},
// (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",
},
}
function genConfig(name) {
const opts = builds[name]
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(
{
css: true,
style:{
postcssModulesOptions:{
generateScopedName: '[name]-[local]-[hash:base64:4]'
}
},
}
),
scss(scssOpts),
typescript({
tsconfig: 'tsconfig.json',
experimentalDecorators: true,
module: 'es2015'
}),
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({}, minify))
}
}
Object.defineProperty(config, "_name", {
enumerable: false,
value: name
})
return config
}
const target = process.env.TARGET || "esm"
module.exports = genConfig(target)