unpkg/rollup.config.js

128 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-01-06 00:50:05 +00:00
const path = require('path');
const builtinModules = require('module').builtinModules;
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const json = require('rollup-plugin-json');
const replace = require('rollup-plugin-replace');
const resolve = require('rollup-plugin-node-resolve');
const url = require('rollup-plugin-url');
const entryManifest = require('./plugins/entryManifest');
2019-01-06 00:50:05 +00:00
const env = process.env.NODE_ENV || 'development';
const dev = env === 'development';
// Allow storing env vars in .env in dev.
if (dev) require('dotenv').config();
const manifest = entryManifest();
2019-01-06 02:03:10 +00:00
const client = ['main', 'autoIndex'].map(entryName => {
return {
external: ['react', 'react-dom', '@emotion/core'],
input: `modules/client/${entryName}.js`,
output: {
format: 'iife',
dir: 'public/_client',
entryFileNames: '[name]-[hash].js',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@emotion/core': 'emotionCore'
}
},
plugins: [
manifest.record({ publicPath: '/_client/' }),
babel({ exclude: /node_modules/ }),
json(),
resolve(),
commonjs({
namedExports: {
'node_modules/react/index.js': [
'createContext',
'createElement',
'forwardRef',
'Component',
'Fragment'
]
}
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
}),
url({
limit: 5 * 1024,
publicPath: '/_client/'
})
]
};
});
const secretKey = require('./secretKey');
2019-01-06 00:50:05 +00:00
const fnsPkg = require('./functions/package.json');
const fnsDeps = (dev
? Object.keys(fnsPkg.dependencies).concat(
Object.keys(fnsPkg.devDependencies || {})
)
2019-01-06 00:50:05 +00:00
: Object.keys(fnsPkg.dependencies)
).concat('react-dom/server');
const functions = [
{
external: id => true,
input: path.resolve(__dirname, 'modules/functions/index.js'),
output: { file: 'functions/index.js', format: 'cjs' },
2019-01-06 00:50:05 +00:00
plugins: [
babel(),
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
})
2019-01-06 00:50:05 +00:00
]
}
].concat(
[
// 'serveAuth',
'serveMainPage',
'serveNpmPackageFile',
'servePublicKey',
'serveStats'
].map(functionName => {
return {
external: builtinModules.concat(fnsDeps),
input: path.resolve(__dirname, `modules/functions/${functionName}.js`),
output: { file: `functions/${functionName}.js`, format: 'cjs' },
plugins: [
manifest.inject({ virtualId: 'entry-manifest' }),
babel({ exclude: /node_modules/ }),
json(),
resolve(),
2019-01-13 03:32:16 +00:00
commonjs(),
url({
limit: 5 * 1024,
publicPath: '/_client/',
emitFiles: false
}),
replace({
'process.env.CLOUDFLARE_EMAIL': JSON.stringify(
process.env.CLOUDFLARE_EMAIL
),
'process.env.CLOUDFLARE_KEY': JSON.stringify(
process.env.CLOUDFLARE_KEY
),
2019-01-16 00:43:52 +00:00
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.NPM_REGISTRY_URL': JSON.stringify(
process.env.NPM_REGISTRY_URL
),
2019-01-15 15:56:40 +00:00
'process.env.ORIGIN': JSON.stringify(process.env.ORIGIN),
'process.env.SECRET_KEY': JSON.stringify(secretKey)
})
]
};
})
);
2019-01-06 00:50:05 +00:00
module.exports = client.concat(functions);