Nuxt/rollup.config.js

105 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-06-16 12:42:45 +00:00
// Some parts brought from https://github.com/vuejs/vue/blob/dev/build/config.js
const { resolve } = require('path')
const rollupBabel = require('rollup-plugin-babel')
const rollupAlias = require('rollup-plugin-alias')
const rollupCommonJS = require('rollup-plugin-commonjs')
const rollupReplace = require('rollup-plugin-replace')
2017-06-18 10:40:49 +00:00
const rollupNodeResolve = require('rollup-plugin-node-resolve')
2017-06-18 07:36:00 +00:00
const packageJson = require('./package.json')
2017-06-16 12:42:45 +00:00
const dependencies = Object.keys(packageJson.dependencies)
const version = packageJson.version || process.env.VERSION
// -----------------------------
// Banner
// -----------------------------
const banner =
'/*!\n' +
' * Nuxt.js v' + version + '\n' +
' * Released under the MIT License.\n' +
' */'
// -----------------------------
// Aliases
// -----------------------------
2017-06-18 07:36:00 +00:00
const rootDir = resolve(__dirname)
const libDir = resolve(rootDir, 'lib')
2017-06-16 12:42:45 +00:00
const distDir = resolve(rootDir, 'dist')
const aliases = {
2017-06-18 07:36:00 +00:00
core: resolve(libDir, 'core/index.js'),
builder: resolve(libDir, 'builder/index.js'),
common: resolve(libDir, 'common/index.js'),
utils: resolve(libDir, 'common/utils.js'),
app: resolve(libDir, 'app'),
2017-06-16 12:42:45 +00:00
}
// -----------------------------
// Builds
// -----------------------------
const builds = {
core: {
2017-06-18 07:36:00 +00:00
entry: resolve(libDir, 'core/index.js'),
2017-06-16 12:42:45 +00:00
dest: resolve(distDir, 'core.js')
},
builder: {
2017-06-18 07:36:00 +00:00
entry: resolve(libDir, 'builder/index.js'),
2017-06-16 12:42:45 +00:00
dest: resolve(distDir, 'builder.js')
}
}
// -----------------------------
// Default config
// -----------------------------
function genConfig (opts) {
const config = {
entry: opts.entry,
dest: opts.dest,
2017-06-18 09:38:52 +00:00
external: ['fs', 'path', 'http'].concat(dependencies, opts.external),
2017-06-16 12:42:45 +00:00
format: opts.format || 'cjs',
banner: opts.banner || banner,
moduleName: opts.moduleName || 'Nuxt',
sourceMap: true,
plugins: [
rollupAlias(Object.assign({
resolve: ['.js', '.json', '.jsx', '.ts']
}, aliases, opts.alias)),
rollupBabel(Object.assign({
exclude: 'node_modules/**',
plugins: [
['transform-runtime', { 'helpers': false, 'polyfill': false }],
'transform-async-to-generator',
'array-includes'
],
presets: [
'babel-preset-es2015-rollup'
]
}, opts.babel)),
2017-06-18 10:59:46 +00:00
rollupNodeResolve({ main: true, jsnext: true }),
rollupCommonJS(),
2017-06-16 12:42:45 +00:00
rollupReplace({
__VERSION__: version
})
].concat(opts.plugins || [])
}
if (opts.env) {
config.plugins.push(rollupReplace({
'process.env.NODE_ENV': JSON.stringify(opts.env)
}))
}
return config
}
if (process.env.TARGET) {
module.exports = genConfig(builds[process.env.TARGET])
} else {
exports.getBuild = name => genConfig(builds[name])
exports.getAllBuilds = () => Object.keys(builds).map(name => genConfig(builds[name]))
}