From 0024f42cfc7740531d2f6a5bf7132a352257a341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 27 Mar 2018 15:53:47 +0200 Subject: [PATCH 1/2] Fix Storybook --- .babelrc | 52 +++++++++++++++++++ .babelrc.js | 40 -------------- package.json | 4 +- .../__snapshots__/FormattedVal.test.js.snap | 12 ++--- yarn.lock | 8 +-- 5 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 .babelrc delete mode 100644 .babelrc.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..622aaf4d --- /dev/null +++ b/.babelrc @@ -0,0 +1,52 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "loose": true, + "modules": false, + "targets": { + "electron": "1.8", + "node": "current" + } + } + ], + "@babel/preset-flow", + "@babel/preset-react", + "@babel/preset-stage-0" + ], + "plugins": [ + ["babel-plugin-module-resolver", { "root": ["src"] }], + [ + "babel-plugin-styled-components", + { + "displayName": false, + "minify": true, + "ssr": true + } + ] + ], + "env": { + "test": { + "presets": [ + [ + "@babel/preset-env", + { + "modules": "commonjs" + } + ] + ] + }, + "development": { + "plugins": [ + [ + "babel-plugin-styled-components", + { + "displayName": true, + "minify": false + } + ] + ] + } + } +} diff --git a/.babelrc.js b/.babelrc.js deleted file mode 100644 index 236441e0..00000000 --- a/.babelrc.js +++ /dev/null @@ -1,40 +0,0 @@ -const { NODE_ENV } = process.env - -const presets = [ - [ - '@babel/preset-env', - { - loose: true, - modules: NODE_ENV === 'test' ? 'commonjs' : false, - targets: { - electron: '1.8', - node: 'current', - }, - }, - ], - '@babel/preset-flow', - '@babel/preset-react', - '@babel/preset-stage-0', -] - -const plugins = [ - ['babel-plugin-module-resolver', { root: ['src'] }], - [ - 'babel-plugin-styled-components', - { - displayName: NODE_ENV === 'development', - minify: NODE_ENV === 'production', - }, - ], -] - -module.exports = { - presets, - plugins, - env: { - test: { - presets, - plugins, - }, - }, -} diff --git a/package.json b/package.json index feadb2f5..d54029ef 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "publish-storybook": "bash ./scripts/publish-storybook.sh", "release": "build", "start": "bash ./scripts/start.sh", - "storybook": "STORYBOOK_ENV=1 start-storybook -s ./static -p 4444", + "storybook": "NODE_ENV=development STORYBOOK_ENV=1 start-storybook -s ./static -p 4444", "trans": "node scripts/trans" }, "lint-staged": { @@ -105,7 +105,7 @@ "@storybook/addon-options": "^3.3.15", "@storybook/addons": "^3.3.15", "@storybook/react": "^3.3.15", - "babel-core": "^7.0.0-0", + "babel-core": "7.0.0-bridge.0", "babel-eslint": "^8.2.1", "babel-jest": "^22.4.3", "babel-plugin-module-resolver": "^3.1.1", diff --git a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap b/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap index 07e26820..07a9dd35 100644 --- a/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap +++ b/src/components/base/FormattedVal/__tests__/__snapshots__/FormattedVal.test.js.snap @@ -2,7 +2,7 @@ exports[`components FormattedVal renders a fiat 1`] = ` 20.00 @@ -11,7 +11,7 @@ exports[`components FormattedVal renders a fiat 1`] = ` exports[`components FormattedVal renders a formatted val 1`] = ` 4 @@ -20,7 +20,7 @@ exports[`components FormattedVal renders a formatted val 1`] = ` exports[`components FormattedVal renders a percent 1`] = ` 30 % @@ -29,7 +29,7 @@ exports[`components FormattedVal renders a percent 1`] = ` exports[`components FormattedVal shows code 1`] = ` BTC 4 @@ -38,7 +38,7 @@ exports[`components FormattedVal shows code 1`] = ` exports[`components FormattedVal shows sign 1`] = ` + 4 @@ -47,7 +47,7 @@ exports[`components FormattedVal shows sign 1`] = ` exports[`components FormattedVal shows sign 2`] = ` - 4 diff --git a/yarn.lock b/yarn.lock index c8481443..adfa25da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1676,6 +1676,10 @@ babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: esutils "^2.0.2" js-tokens "^3.0.2" +babel-core@7.0.0-bridge.0: + version "7.0.0-bridge.0" + resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" + babel-core@^6.0.0, babel-core@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8" @@ -1700,10 +1704,6 @@ babel-core@^6.0.0, babel-core@^6.26.0: slash "^1.0.0" source-map "^0.5.6" -babel-core@^7.0.0-0: - version "7.0.0-bridge.0" - resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" - babel-eslint@^8.2.1: version "8.2.2" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.2.tgz#1102273354c6f0b29b4ea28a65f97d122296b68b" From ac78f5df3d7a822c3578eafd3b75ca57bc56f706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 27 Mar 2018 17:18:56 +0200 Subject: [PATCH 2/2] Use REAL babel.config in electron-webpack --- .babelrc | 51 +------------------------------------ babel.config.js | 32 +++++++++++++++++++++++ package.json | 1 + scripts/dist.sh | 4 +-- scripts/start.sh | 2 +- webpack/internals.config.js | 6 ++++- webpack/main.config.js | 5 ++++ webpack/renderer.config.js | 5 ++++ webpack/rules.js | 12 +++++++++ 9 files changed, 64 insertions(+), 54 deletions(-) create mode 100644 babel.config.js create mode 100644 webpack/rules.js diff --git a/.babelrc b/.babelrc index 622aaf4d..3aa02e72 100644 --- a/.babelrc +++ b/.babelrc @@ -1,52 +1,3 @@ { - "presets": [ - [ - "@babel/preset-env", - { - "loose": true, - "modules": false, - "targets": { - "electron": "1.8", - "node": "current" - } - } - ], - "@babel/preset-flow", - "@babel/preset-react", - "@babel/preset-stage-0" - ], - "plugins": [ - ["babel-plugin-module-resolver", { "root": ["src"] }], - [ - "babel-plugin-styled-components", - { - "displayName": false, - "minify": true, - "ssr": true - } - ] - ], - "env": { - "test": { - "presets": [ - [ - "@babel/preset-env", - { - "modules": "commonjs" - } - ] - ] - }, - "development": { - "plugins": [ - [ - "babel-plugin-styled-components", - { - "displayName": true, - "minify": false - } - ] - ] - } - } + "presets": ["./babel.config.js"] } diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 00000000..3e5f9bc5 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,32 @@ +const { NODE_ENV } = process.env + +const __TEST__ = NODE_ENV === 'test' + +module.exports = () => ({ + presets: [ + [ + require('@babel/preset-env'), + { + loose: true, + modules: __TEST__ ? 'commonjs' : false, + targets: { + electron: '1.8', + node: 'current', + }, + }, + ], + require('@babel/preset-flow'), + require('@babel/preset-react'), + require('@babel/preset-stage-0'), + ], + plugins: [ + [require('babel-plugin-module-resolver'), { root: ['src'] }], + [ + require('babel-plugin-styled-components'), + { + displayName: NODE_ENV === 'development', + ssr: __TEST__, + }, + ], + ], +}) diff --git a/package.json b/package.json index d54029ef..310e6c24 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "babel-core": "7.0.0-bridge.0", "babel-eslint": "^8.2.1", "babel-jest": "^22.4.3", + "babel-loader": "^8.0.0-beta.2", "babel-plugin-module-resolver": "^3.1.1", "babel-plugin-styled-components": "^1.5.0", "chalk": "^2.3.1", diff --git a/scripts/dist.sh b/scripts/dist.sh index 2466bf65..7a7fe9eb 100755 --- a/scripts/dist.sh +++ b/scripts/dist.sh @@ -1,5 +1,5 @@ #/bin/bash rm -rf dist && -NODE_ENV=production webpack-cli --config webpack/internals.config.js && -electron-webpack +NODE_ENV=production webpack-cli --mode production --config webpack/internals.config.js && +NODE_ENV=production electron-webpack diff --git a/scripts/start.sh b/scripts/start.sh index ddba5331..f0da05f1 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,5 +1,5 @@ #/bin/bash concurrently --raw \ - "cross-env NODE_ENV=development webpack-cli --watch --config webpack/internals.config.js" \ + "cross-env NODE_ENV=development webpack-cli --mode development --watch --config webpack/internals.config.js" \ "cross-env NODE_ENV=development electron-webpack dev" diff --git a/webpack/internals.config.js b/webpack/internals.config.js index 2cc52244..16350da3 100644 --- a/webpack/internals.config.js +++ b/webpack/internals.config.js @@ -4,6 +4,7 @@ const webpackMain = require('electron-webpack/webpack.main.config') const plugins = require('./plugins') const resolve = require('./resolve') +const rules = require('./rules') const dirs = p => fs @@ -40,7 +41,10 @@ module.exports = webpackMain().then(config => ({ path: path.resolve(__dirname, '../dist/internals'), }, - module: config.module, + module: { + ...config.module, + rules, + }, plugins: [...plugins('internals'), ...config.plugins], })) diff --git a/webpack/main.config.js b/webpack/main.config.js index 753d2dee..95764b38 100644 --- a/webpack/main.config.js +++ b/webpack/main.config.js @@ -1,9 +1,14 @@ const plugins = require('./plugins') const resolve = require('./resolve') +const rules = require('./rules') const config = { + mode: __ENV__, plugins: plugins('main'), resolve, + module: { + rules, + }, } module.exports = config diff --git a/webpack/renderer.config.js b/webpack/renderer.config.js index 63251673..6e0b44e2 100644 --- a/webpack/renderer.config.js +++ b/webpack/renderer.config.js @@ -2,10 +2,15 @@ const HardSourceWebpackPlugin = require('hard-source-webpack-plugin') const plugins = require('./plugins') const resolve = require('./resolve') +const rules = require('./rules') const config = { + mode: __ENV__, resolve, plugins: [...plugins('renderer'), new HardSourceWebpackPlugin()], + module: { + rules, + }, devServer: { historyApiFallback: true, }, diff --git a/webpack/rules.js b/webpack/rules.js new file mode 100644 index 00000000..ccdaa731 --- /dev/null +++ b/webpack/rules.js @@ -0,0 +1,12 @@ +const babelConfig = require('../babel.config') + +module.exports = [ + { + test: /\.js$/, + loader: 'babel-loader', + options: { + babelrc: false, + ...babelConfig(), + }, + }, +]