Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-preset-env #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"homepage": "https://github.com/Rich-Harris/packd#readme",
"dependencies": {
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"browserify": "^14.1.0",
"compression": "^1.7.0",
"etag": "^1.8.0",
Expand All @@ -36,6 +39,7 @@
"request": "^2.81.0",
"request-promise": "^4.2.1",
"rollup": "^0.45.2",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"sander": "^0.6.0",
Expand Down
34 changes: 29 additions & 5 deletions server/child-processes/create-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const resolve = require( 'rollup-plugin-node-resolve' );
const UglifyJS = require( 'uglify-js' );
const isModule = require( 'is-module' );
const makeLegalIdentifier = require( '../utils/makeLegalIdentifier' );
const babel = require( 'rollup-plugin-babel' );

const { npmInstallEnvVars, root, tmpdir } = require( '../../config.js' );

Expand Down Expand Up @@ -130,9 +131,15 @@ function bundle ( cwd, deep, query ) {

const code = sander.readFileSync( entry, { encoding: 'utf-8' });

let babelPresetEnvTarget;

if (typeof query.target === 'string') {
babelPresetEnvTarget = query.target;
}

if ( isModule( code ) ) {
info( `[${pkg.name}] ES2015 module found, using Rollup` );
return bundleWithRollup( cwd, pkg, entry, moduleName );
return bundleWithRollup( cwd, pkg, entry, moduleName, babelPresetEnvTarget );
} else {
info( `[${pkg.name}] No ES2015 module found, using Browserify` );
return bundleWithBrowserify( pkg, entry, moduleName );
Expand All @@ -149,12 +156,29 @@ function findEntry ( file ) {
}
}

async function bundleWithRollup ( cwd, pkg, moduleEntry, moduleName ) {
async function bundleWithRollup ( cwd, pkg, moduleEntry, moduleName, babelPresetEnvTarget ) {
const plugins = [
resolve({ module: true, jsnext: true, main: false, modulesOnly: true }),
];

if (typeof babelPresetEnvTarget === 'string') {
plugins.push(
babel({
babelrc: false,
presets: [
"flow",
["babel-preset-env", {
target: babelPresetEnvTarget,
modules: false
}]
]
})
);
}

const bundle = await rollup.rollup({
entry: path.resolve( cwd, moduleEntry ),
plugins: [
resolve({ module: true, jsnext: true, main: false, modulesOnly: true })
]
plugins
});

info( `[${pkg.name}] bundled using Rollup` );
Expand Down