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] 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(), + }, + }, +]