-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from Financial-Times/matth/shared-rollup
Shared rollup configuration
- Loading branch information
Showing
18 changed files
with
158 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const xRollup = require('@financial-times/x-rollup'); | ||
const pkg = require('./package.json'); | ||
|
||
xRollup({ input: './src/Increment.jsx', pkg }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const xRollup = require('@financial-times/x-rollup'); | ||
const pkg = require('./package.json'); | ||
|
||
xRollup({ input: './src/Interaction.jsx', pkg }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const xRollup = require('@financial-times/x-rollup'); | ||
const pkg = require('./package.json'); | ||
|
||
xRollup({ input: './src/Button.jsx', pkg }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const xRollup = require('@financial-times/x-rollup'); | ||
const pkg = require('./package.json'); | ||
|
||
xRollup({ input: './src/Teaser.jsx', pkg }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,19 @@ | ||
const babel = require('rollup-plugin-babel'); | ||
const commonjs = require('rollup-plugin-commonjs'); | ||
const postcss = require('rollup-plugin-postcss'); | ||
const path = require('path'); | ||
/* eslint no-console:off */ | ||
|
||
const resolvePlugin = (plugin) => Array.isArray(plugin) | ||
? [require.resolve(plugin[0]), plugin[1]] | ||
: require.resolve(plugin); | ||
const rollup = require('rollup'); | ||
const rollupConfig = require('./src/rollup-config'); | ||
|
||
const babelOptions = (targets) => ({ | ||
include: '**/*.{js,jsx}', | ||
plugins: [ | ||
['babel-plugin-transform-react-jsx', { | ||
pragma: 'h', | ||
useBuiltIns: true, | ||
}], | ||
['babel-plugin-transform-object-rest-spread', { | ||
// although this is stage 4, we'd have to use babel 7 to get the version | ||
// of preset-env that supports it :/ | ||
useBuiltIns: true, | ||
}], | ||
'babel-plugin-external-helpers', | ||
['fast-async', { | ||
compiler: { | ||
noRuntime: true, | ||
}, | ||
}], | ||
].map(resolvePlugin), | ||
module.exports = async (options) => { | ||
const config = rollupConfig(options); | ||
|
||
presets: targets && [ | ||
['babel-preset-env', { | ||
targets, | ||
modules: false, | ||
exclude: ['transform-regenerator', 'transform-async-to-generator'], | ||
}], | ||
].map(resolvePlugin), | ||
}); | ||
|
||
module.exports = ({input, pkg, external: extraExternal = []}) => { | ||
const external = [ | ||
'@financial-times/x-engine', | ||
...extraExternal, | ||
]; | ||
|
||
const commonPlugin = commonjs({ extensions: ['.js', '.jsx'] }); | ||
const postcssPlugin = pkg.style && postcss({ | ||
extract: pkg.style, | ||
modules: true, | ||
use: [ | ||
['sass', { | ||
includePaths: [path.resolve(process.cwd(), 'bower_components')] | ||
}], | ||
'stylus', | ||
'less', | ||
], | ||
}); | ||
|
||
return [ | ||
{ | ||
input, | ||
output: { | ||
file: pkg.module, | ||
format: 'es' | ||
}, | ||
external, | ||
plugins: [ | ||
babel(babelOptions({ node: 6 })), | ||
postcssPlugin, | ||
commonPlugin | ||
].filter(Boolean), | ||
}, | ||
{ | ||
input, | ||
output: { | ||
file: pkg.main, | ||
format: 'cjs' | ||
}, | ||
external, | ||
plugins: [ | ||
babel(babelOptions({ node: 6 })), | ||
postcssPlugin, | ||
commonPlugin, | ||
].filter(Boolean), | ||
}, | ||
{ | ||
input, | ||
output: { | ||
file: pkg.browser, | ||
format: 'cjs' | ||
}, | ||
external, | ||
plugins: [ | ||
babel(babelOptions({ browsers: ['ie 11'] })), | ||
postcssPlugin, | ||
commonPlugin, | ||
].filter(Boolean), | ||
for (const [input, output] of config) { | ||
try { | ||
console.log(`Bundling ${input.input} ➡ ${output.file}…`); | ||
const bundle = await rollup.rollup(input); | ||
await bundle.write(output); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
]; | ||
} | ||
}; | ||
|
||
module.exports.babelOptions = babelOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports = (targets = []) => ({ | ||
include: '**/*.{js,jsx}', | ||
plugins: [ | ||
// this plugin is not React specific! It includes a general JSX parser and helper 🙄 | ||
[ | ||
require.resolve('babel-plugin-transform-react-jsx'), | ||
{ | ||
pragma: 'h', | ||
useBuiltIns: true | ||
} | ||
], | ||
// Although this feature is at stage 4, we'd have to use babel 7 to get the version | ||
// of preset-env that actually supports it 😖 | ||
[ | ||
require.resolve('babel-plugin-transform-object-rest-spread'), | ||
{ | ||
useBuiltIns: true | ||
} | ||
], | ||
// Instruct Babel to not include any internal helper declarations in the output | ||
require.resolve('babel-plugin-external-helpers'), | ||
// Implements async/await using syntax transformation rather than generators which require | ||
// a huge runtime for browsers which do not natively support them. | ||
[ | ||
require.resolve('fast-async'), | ||
{ | ||
compiler: { | ||
noRuntime: true | ||
} | ||
} | ||
] | ||
], | ||
presets: [ | ||
[ | ||
require.resolve('babel-preset-env'), | ||
{ | ||
targets, | ||
modules: false, | ||
exclude: ['transform-regenerator', 'transform-async-to-generator'] | ||
} | ||
] | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const path = require('path'); | ||
|
||
module.exports = (style) => { | ||
return { | ||
extract: style, | ||
modules: true, | ||
use: [ | ||
[ | ||
'sass', | ||
{ | ||
includePaths: [path.resolve(process.cwd(), 'bower_components')] | ||
} | ||
], | ||
'stylus', | ||
'less' | ||
] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const babel = require('rollup-plugin-babel'); | ||
const postcss = require('rollup-plugin-postcss'); | ||
const commonjs = require('rollup-plugin-commonjs'); | ||
const postcssConfig = require('./postcss-config'); | ||
const babelConfig = require('./babel-config'); | ||
|
||
module.exports = ({ input, pkg }) => { | ||
// Don't bundle any dependencies | ||
const external = Object.keys(pkg.dependencies); | ||
|
||
const plugins = [ | ||
// Convert CommonJS modules to ESM so they can be included in the bundle | ||
commonjs({ extensions: ['.js', '.jsx'] }) | ||
]; | ||
|
||
// Add support for CSS modules (and any required transpilation) | ||
if (pkg.style) { | ||
const config = postcssConfig(pkg.style); | ||
plugins.push(postcss(config)); | ||
} | ||
|
||
// Pairs of input and output options | ||
return [ | ||
[ | ||
{ | ||
input, | ||
external, | ||
plugins: [babel(babelConfig({ node: 6 })), ...plugins] | ||
}, | ||
{ | ||
file: pkg.module, | ||
format: 'es' | ||
} | ||
], | ||
[ | ||
{ | ||
input, | ||
external, | ||
plugins: [babel(babelConfig({ node: 6 })), ...plugins] | ||
}, | ||
{ | ||
file: pkg.main, | ||
format: 'cjs' | ||
} | ||
], | ||
[ | ||
{ | ||
input, | ||
external, | ||
plugins: [babel(babelConfig({ browsers: ['ie 11'] })), ...plugins] | ||
}, | ||
{ | ||
file: pkg.browser, | ||
format: 'cjs' | ||
} | ||
] | ||
]; | ||
}; |