diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..3aa02e72 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["./babel.config.js"] +} 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/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 56a78dbe..1c293a97 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": { @@ -106,9 +106,10 @@ "@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-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/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/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(), + }, + }, +] diff --git a/yarn.lock b/yarn.lock index ff0ed7cb..06cbc0d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1689,6 +1689,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" @@ -1713,10 +1717,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"