Nuxt/build/rollup.config.js

117 lines
3.1 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')
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
// -----------------------------
const rootDir = resolve(__dirname, '..')
2017-06-18 07:36:00 +00:00
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 = {
2017-06-20 12:12:21 +00:00
nuxt: {
entry: resolve(libDir, 'index.js'),
2017-08-29 14:08:23 +00:00
file: resolve(distDir, 'nuxt.js')
2017-06-20 12:12:21 +00:00
},
2017-06-16 12:42:45 +00:00
core: {
2017-06-18 07:36:00 +00:00
entry: resolve(libDir, 'core/index.js'),
2017-08-29 14:08:23 +00:00
file: resolve(distDir, 'core.js')
2017-06-16 12:42:45 +00:00
}
}
// -----------------------------
// Default config
// -----------------------------
2017-11-25 13:52:42 +00:00
function genConfig(opts) {
2017-06-16 12:42:45 +00:00
const config = {
2017-08-29 14:08:23 +00:00
input: opts.entry,
output: {
file: opts.file,
format: 'cjs',
sourcemap: true
},
external: ['fs', 'path', 'http', 'module', 'vue-server-renderer/server-plugin', 'vue-server-renderer/client-plugin']
.concat(dependencies, opts.external),
2017-06-16 12:42:45 +00:00
banner: opts.banner || banner,
2017-08-29 14:08:23 +00:00
name: opts.modulename || 'Nuxt',
2017-06-16 12:42:45 +00:00
plugins: [
rollupAlias(Object.assign({
resolve: ['.js', '.json', '.jsx', '.ts']
}, aliases, opts.alias)),
2017-08-29 14:08:23 +00:00
rollupNodeResolve({ preferBuiltins: true }),
rollupCommonJS(),
2017-06-16 12:42:45 +00:00
rollupBabel(Object.assign({
exclude: 'node_modules/**',
plugins: [
['transform-runtime', { 'helpers': false, 'polyfill': false }],
'transform-async-to-generator',
2017-08-29 14:08:23 +00:00
'array-includes',
'external-helpers'
2017-06-16 12:42:45 +00:00
],
presets: [
['env', {
targets: {
node: '6.11.0'
},
modules: false
}]
],
'env': {
'test': {
'plugins': [ 'istanbul' ]
}
}
2017-06-16 12:42:45 +00:00
}, opts.babel)),
2017-08-29 14:08:23 +00:00
rollupReplace({ __VERSION__: version })
2017-06-16 12:42:45 +00:00
].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]))
}