Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Refactor babel configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Aug 29, 2018
1 parent 542ce43 commit d4518d9
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 252 deletions.
62 changes: 0 additions & 62 deletions build/babel-fusion-preset.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ const fs = require('fs');
const test = require('tape');
const {transformFileSync} = require('@babel/core');
const plugin = require('../');
const {globalsPreset} = require('../../../babel-fusion-preset.js');

test('boolean expression transformed', t => {
const output = transformFileSync(
__dirname + '/fixtures/input-boolean-expression',
{
presets: [
[
globalsPreset,
{
target: 'browser',
transformGlobals: true,
assumeNoImportSideEffects: true,
},
],
plugins: [
[require('babel-plugin-transform-cup-globals'), {target: 'browser'}],
[plugin, {target: 'browser'}],
],
}
);
Expand Down
19 changes: 0 additions & 19 deletions build/babel-preset.js

This file was deleted.

57 changes: 0 additions & 57 deletions build/babel-transpilation-preset.js

This file was deleted.

18 changes: 0 additions & 18 deletions build/browser-support.js

This file was deleted.

106 changes: 45 additions & 61 deletions build/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
} = require('../lib/compression');
const resolveFrom = require('resolve-from');

const getBabelConfig = require('./get-babel-config.js');
const LoaderContextProviderPlugin = require('./plugins/loader-context-provider-plugin.js');
const {chunkIdsLoader, fileLoader} = require('./loaders/index.js');
const {DeferredState} = require('./shared-state-containers.js');
Expand All @@ -34,7 +35,6 @@ const InstrumentedImportDependencyTemplatePlugin = require('./plugins/instrument
const I18nDiscoveryPlugin = require('./i18n-discovery-plugin.js');
const ClientChunkBundleUrlMapPlugin = require('./client-chunk-bundle-url-map-plugin');
const SyncChunkIdsPlugin = require('./sync-chunk-ids-plugin');
const browserSupport = require('./browser-support');
const chalk = require('chalk');
const webpackHotMiddleware = require('webpack-hot-middleware');
const loadFusionRC = require('./load-fusionrc.js');
Expand Down Expand Up @@ -94,15 +94,6 @@ function getConfig({target, env, dir, watch, state}) {
`process.env.NODE_ENV = '${nodeEnv}';` +
`}`;

const targets =
target === 'node'
? {
node: 'current',
}
: {
browsers: browserSupport.conservative,
};

return {
name,
target,
Expand Down Expand Up @@ -204,25 +195,19 @@ function getConfig({target, env, dir, watch, state}) {
loader: require.resolve('babel-loader'),
options: {
cacheDirectory: `${dir}/node_modules/.fusion_babel_cache`,
plugins: [
// Note: plugins run first to last, so user-defined plugins go first
...(fusionConfig.babel && fusionConfig.babel.plugins
? fusionConfig.babel.plugins
: []),
],
presets: [
// Note: presets run last to first, so user-defined presets go last
[
require.resolve('./babel-transpilation-preset.js'),
{
targets,
},
],
...(fusionConfig.babel && fusionConfig.babel.presets
? fusionConfig.babel.presets
: []),
],

...getBabelConfig({
runtime:
target === 'node' ? 'node-bundled' : 'browser-legacy',
specOnly: true,
plugins:
fusionConfig.babel && fusionConfig.babel.plugins
? fusionConfig.babel.plugins
: [],
presets:
fusionConfig.babel && fusionConfig.babel.presets
? fusionConfig.babel.presets
: [],
}),
/**
* Fusion-specific transforms (not applied to node_modules)
*/
Expand All @@ -235,40 +220,39 @@ function getConfig({target, env, dir, watch, state}) {
entry,
/fusion-cli\/entries/,
],
plugins: [
//cup-globals works with webpack.EnvironmentPlugin(['NODE_ENV']) to implement static conditionals
require.resolve('./babel-plugins/babel-plugin-asseturl'),
require.resolve(
'./babel-plugins/babel-plugin-pure-create-plugin'
),
require.resolve(
'./babel-plugins/babel-plugin-sync-chunk-ids'
),
require.resolve(
'./babel-plugins/babel-plugin-sync-chunk-paths'
),
require.resolve('./babel-plugins/babel-plugin-chunkid'),
pragma && [
require.resolve('@babel/plugin-transform-react-jsx'),
{pragma},
],
target === 'web' &&
require.resolve('./babel-plugins/babel-plugin-i18n'),
].filter(Boolean),
presets: [
[
require.resolve('./babel-fusion-preset.js'),
{
targets,
assumeNoImportSideEffects:
fusionConfig.assumeNoImportSideEffects,
},
],
],
...getBabelConfig({
dev: env === 'development',
transformGlobals: true,
assumeNoImportSideEffects:
fusionConfig.assumeNoImportSideEffects,
runtime:
target === 'node' ? 'node-bundled' : 'browser-legacy',
specOnly: false,
plugins: [
//cup-globals works with webpack.EnvironmentPlugin(['NODE_ENV']) to implement static conditionals
require.resolve(
'./babel-plugins/babel-plugin-asseturl'
),
require.resolve(
'./babel-plugins/babel-plugin-pure-create-plugin'
),
require.resolve(
'./babel-plugins/babel-plugin-sync-chunk-ids'
),
require.resolve(
'./babel-plugins/babel-plugin-sync-chunk-paths'
),
require.resolve('./babel-plugins/babel-plugin-chunkid'),
pragma && [
require.resolve('@babel/plugin-transform-react-jsx'),
{pragma},
],
target === 'web' &&
require.resolve('./babel-plugins/babel-plugin-i18n'),
].filter(Boolean),
}),
},
],

babelrc: false,
},
},
],
Expand Down
33 changes: 15 additions & 18 deletions build/jest/jest-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,27 @@
/* eslint-env node */

const loadFusionRC = require('../load-fusionrc.js');

const babelConfig = require('../babel-preset.js')(null, {
targets: {
node: 'current',
},
modules: 'commonjs',
transformGlobals: false,
});
const getBabelConfig = require('../get-babel-config.js');

const fusionConfig = loadFusionRC(process.cwd());

if (!babelConfig.plugins) {
babelConfig.plugins = [];
}

babelConfig.plugins.push(require.resolve('babel-plugin-dynamic-import-node'));
let customPlugins;
let customPresets;

if (fusionConfig.babel && fusionConfig.babel.plugins) {
// Run user-defined plugins first
babelConfig.plugins = fusionConfig.babel.plugins.concat(
...babelConfig.plugins
);
if (fusionConfig.babel) {
customPlugins = fusionConfig.babel.plugins;
customPresets = fusionConfig.babel.presets;
}

const babelConfig = getBabelConfig({
runtime: 'node-native',
specOnly: false,
plugins: customPlugins,
presets: customPresets,
dev: false,
transformGlobals: false,
});

const transformer = require('babel-jest').createTransformer(babelConfig);

module.exports = transformer;
7 changes: 3 additions & 4 deletions entries/client-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

// Require is used to opt out of webpack tree-shaking of ununsed imports
// See: https://github.com/webpack/webpack/issues/6571
require('core-js/es6'); // eslint-disable-line
require('core-js/es7'); // eslint-disable-line
require("core-js"); // eslint-disable-line

/*
Webpack has a configuration option called `publicPath`, which determines the
Expand All @@ -35,12 +34,12 @@ into `__webpack_require__.p = ...` and uses it for HMR manifest requests

/* eslint-disable */
// $FlowFixMe
__webpack_public_path__ = window.__WEBPACK_PUBLIC_PATH__ + '/';
__webpack_public_path__ = window.__WEBPACK_PUBLIC_PATH__ + "/";
/* eslint-enable */

function reload() {
// $FlowFixMe
const main = require('__FRAMEWORK_SHARED_ENTRY__'); // eslint-disable-line
const main = require("__FRAMEWORK_SHARED_ENTRY__"); // eslint-disable-line
const initialize = main.default || main;
Promise.resolve(initialize()).then(app => {
app.callback().call();
Expand Down
Loading

0 comments on commit d4518d9

Please sign in to comment.