Skip to content

Commit

Permalink
Use babelrc: false only for custom config in .storybook directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi committed Aug 25, 2018
1 parent 1bf84ee commit 7a86aa7
Show file tree
Hide file tree
Showing 94 changed files with 1,112 additions and 42 deletions.
1 change: 1 addition & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-dom": "^16.4.2",
"sass-loader": "^7.1.0",
"ts-loader": "^4.4.2",
"webpack": "^4.16.4",
"zone.js": "^0.8.26"
},
"peerDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions app/angular/src/server/wrapInitialConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';
import { ContextReplacementPlugin } from 'webpack';
import loadTsConfig from './ts_config';

export default (config, configDir) => ({
Expand Down Expand Up @@ -35,4 +37,9 @@ export default (config, configDir) => ({
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(/@angular(\\|\/)core(\\|\/)fesm5/, path.resolve(__dirname, '..')),
],
});
3 changes: 2 additions & 1 deletion app/polymer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"common-tags": "^1.8.0",
"global": "^4.3.2",
"react": "^16.4.2",
"react-dom": "^16.4.2"
"react-dom": "^16.4.2",
"webpack": "^4.16.4"
},
"devDependencies": {
"lit-html": "^0.10.2",
Expand Down
7 changes: 7 additions & 0 deletions app/polymer/src/server/wrapInitialConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IgnorePlugin } from 'webpack';

export default config => ({
...config,
module: {
Expand All @@ -16,4 +18,9 @@ export default config => ({
},
],
},
plugins: [
...config.plugins,
// See https://github.com/webcomponents/webcomponentsjs/issues/794#issuecomment-386554298
new IgnorePlugin(/^vertx$/),
],
});
16 changes: 0 additions & 16 deletions lib/cli/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ export function writePackageJson(packageJson) {
fs.writeFileSync(packageJsonPath, content, 'utf8');
}

export function getBabelRc() {
const babelRcPath = path.resolve('.babelrc');
if (!fs.existsSync(babelRcPath)) {
return false;
}

const babelRcContent = fs.readFileSync(babelRcPath, 'utf8');
return JSON.parse(babelRcContent);
}

export function writeBabelRc(babelRc) {
const content = `${JSON.stringify(babelRc, null, 2)}\n`;
const babelRcPath = path.resolve('.babelrc');
Expand Down Expand Up @@ -185,12 +175,6 @@ export async function installBabel(npmOptions, packageJson) {
);
// Babel 6
if (satisfies(latestCompatibleBabelVersion, '^6.0.0')) {
if (!getBabelRc()) {
logger.warn(
chalk.red(`
You have a dependency on Babel 6 but don't have a .babelrc file. Please add one either in project directory or in .storybook.'`)
);
}
babelLoaderVersion = '^7.0.0';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babel_config_js/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: ['@babel/plugin-proposal-optional-chaining'],
};
20 changes: 20 additions & 0 deletions lib/cli/test/fixtures/react_babel_config_js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "react-babel-config-js-fixture",
"version": "1.0.0",
"license": "MIT",
"main": "stories/index.stories.js",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.0.0-rc.3",
"@babel/core": "7.0.0-rc.3",
"babel-loader": "8.0.0-beta.6",
"@storybook/react": "^4.0.0-alpha.17"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { storiesOf } from '@storybook/react';

const data = {
user: {
name: 'Joe',
},
};

storiesOf('My Component', module)
.add('state', () => <span>Hello {data.user?.name}</span>)
3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babel_custom_preset/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["./babel-preset-custom"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = () => ({
plugins: ['@babel/plugin-proposal-optional-chaining'],
});
20 changes: 20 additions & 0 deletions lib/cli/test/fixtures/react_babel_custom_preset/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "react-babel-custom-preset-fixture",
"version": "1.0.0",
"license": "MIT",
"main": "stories/index.stories.js",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.0.0-rc.3",
"@babel/core": "7.0.0-rc.3",
"babel-loader": "8.0.0-beta.6",
"@storybook/react": "^4.0.0-alpha.17"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { storiesOf } from '@storybook/react';

const data = {
user: {
name: 'Joe',
},
};

storiesOf('My Component', module)
.add('state', () => <span>Hello {data.user?.name}</span>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
23 changes: 23 additions & 0 deletions lib/cli/test/fixtures/react_babel_pkg_json/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "react-babel-pkg-json-fixture",
"version": "1.0.0",
"license": "MIT",
"main": "stories/index.stories.js",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.0.0-rc.3",
"@babel/core": "7.0.0-rc.3",
"babel-loader": "8.0.0-beta.6",
"@storybook/react": "^4.0.0-alpha.17"
},
"babel": {
"plugins": ["@babel/plugin-proposal-optional-chaining"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { storiesOf } from '@storybook/react';

const data = {
user: {
name: 'Joe',
},
};

storiesOf('My Component', module)
.add('state', () => <span>Hello {data.user?.name}</span>)
3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babelrc/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-proposal-optional-chaining"]
}
9 changes: 9 additions & 0 deletions lib/cli/test/fixtures/react_babelrc/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
20 changes: 20 additions & 0 deletions lib/cli/test/fixtures/react_babelrc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "react-babelrc-fixture",
"version": "1.0.0",
"license": "MIT",
"main": "stories/index.stories.js",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.0.0-rc.3",
"@babel/core": "7.0.0-rc.3",
"babel-loader": "8.0.0-beta.6",
"@storybook/react": "^4.0.0-alpha.17"
}
}
12 changes: 12 additions & 0 deletions lib/cli/test/fixtures/react_babelrc/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { storiesOf } from '@storybook/react';

const data = {
user: {
name: 'Joe',
},
};

storiesOf('My Component', module)
.add('state', () => <span>Hello {data.user?.name}</span>)
3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_babelrc_js/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: ['@babel/plugin-proposal-optional-chaining'],
};
9 changes: 9 additions & 0 deletions lib/cli/test/fixtures/react_babelrc_js/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { configure } from '@storybook/react';

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
20 changes: 20 additions & 0 deletions lib/cli/test/fixtures/react_babelrc_js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "react-babelrc-js-fixture",
"version": "1.0.0",
"license": "MIT",
"main": "stories/index.stories.js",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "7.0.0-rc.3",
"@babel/core": "7.0.0-rc.3",
"babel-loader": "8.0.0-beta.6",
"@storybook/react": "^4.0.0-alpha.17"
}
}
12 changes: 12 additions & 0 deletions lib/cli/test/fixtures/react_babelrc_js/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { storiesOf } from '@storybook/react';

const data = {
user: {
name: 'Joe',
},
};

storiesOf('My Component', module)
.add('state', () => <span>Hello {data.user?.name}</span>)
3 changes: 3 additions & 0 deletions lib/cli/test/fixtures/react_static/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "react-static/.babelrc"
}
20 changes: 20 additions & 0 deletions lib/cli/test/fixtures/react_static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# dependencies
/node_modules

# testing
/coverage

# production
/dist
/tmp

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
9 changes: 9 additions & 0 deletions lib/cli/test/fixtures/react_static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# React-Static - Blank Example

This example is a blank version of react-static. It includes::
- Babel
- CSS imports
- Image imports
- File imports

To get started, run `react-static create` and use the `blank` template.
24 changes: 24 additions & 0 deletions lib/cli/test/fixtures/react_static/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "react-static-fixture",
"version": "1.0.1",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "react-static start",
"stage": "react-static build --staging",
"build": "react-static build",
"serve": "serve dist -p 3000"
},
"dependencies": {
"axios": "^0.16.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-router": "^4.2.0",
"react-static": "^5"
},
"devDependencies": {
"babel-core":"^6.26.3",
"eslint-config-react-tools": "1.x.x",
"serve": "^6.1.0"
}
}
1 change: 1 addition & 0 deletions lib/cli/test/fixtures/react_static/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User-agent: *
Loading

0 comments on commit 7a86aa7

Please sign in to comment.