From bf40af1ed757c6215d0315f8352ae4fc497f82a0 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Mon, 17 Sep 2018 12:27:37 +0200 Subject: [PATCH] refactor(webpack): move config files out of root Move the Webpack config files out of the root directory and into a more suitable location. This avoids unnecessary clutter of the project root. --- .eslintrc | 2 +- .../webpack/webpack.config.base.js | 20 ++++++++++--------- .../webpack/webpack.config.eslint.js | 0 .../webpack/webpack.config.main.prod.js | 9 +++++---- .../webpack.config.renderer.dev.dll.js | 18 ++++++++--------- .../webpack/webpack.config.renderer.dev.js | 17 ++++++++-------- .../webpack/webpack.config.renderer.prod.js | 10 +++++----- package.json | 10 +++++----- 8 files changed, 43 insertions(+), 43 deletions(-) rename webpack.config.base.js => internals/webpack/webpack.config.base.js (79%) rename webpack.config.eslint.js => internals/webpack/webpack.config.eslint.js (100%) rename webpack.config.main.prod.js => internals/webpack/webpack.config.main.prod.js (85%) rename webpack.config.renderer.dev.dll.js => internals/webpack/webpack.config.renderer.dev.dll.js (90%) rename webpack.config.renderer.dev.js => internals/webpack/webpack.config.renderer.dev.js (93%) rename webpack.config.renderer.prod.js => internals/webpack/webpack.config.renderer.prod.js (94%) diff --git a/.eslintrc b/.eslintrc index a7d519d6..50d24979 100644 --- a/.eslintrc +++ b/.eslintrc @@ -75,7 +75,7 @@ "moduleDirectory": ["app", "app/node_modules", "node_modules"] }, "webpack": { - "config": "webpack.config.eslint.js" + "config": "internals/webpack/webpack.config.eslint.js" } } } diff --git a/webpack.config.base.js b/internals/webpack/webpack.config.base.js similarity index 79% rename from webpack.config.base.js rename to internals/webpack/webpack.config.base.js index 3c546568..f34b239a 100644 --- a/webpack.config.base.js +++ b/internals/webpack/webpack.config.base.js @@ -4,11 +4,20 @@ import path from 'path' import { IgnorePlugin } from 'webpack' -import { dependencies as externals } from './app/package.json' +import { dependencies as externals } from '../../app/package.json' + +export const rootDir = path.join(__dirname, '..', '..') export default { externals: Object.keys(externals || {}), + context: rootDir, + + output: { + // https://github.com/webpack/webpack/issues/1114 + libraryTarget: 'commonjs2' + }, + module: { rules: [ { @@ -24,19 +33,12 @@ export default { ] }, - output: { - path: path.join(__dirname, 'app'), - filename: 'renderer.dev.js', - // https://github.com/webpack/webpack/issues/1114 - libraryTarget: 'commonjs2' - }, - /** * Determine the array of extensions that should be used to resolve modules. */ resolve: { extensions: ['.js', '.jsx', '.json'], - modules: [path.join(__dirname, 'app'), 'node_modules'] + modules: [path.join(rootDir, 'app'), 'node_modules'] }, plugins: [new IgnorePlugin(/^\.\/locale$/, /moment$/)], diff --git a/webpack.config.eslint.js b/internals/webpack/webpack.config.eslint.js similarity index 100% rename from webpack.config.eslint.js rename to internals/webpack/webpack.config.eslint.js diff --git a/webpack.config.main.prod.js b/internals/webpack/webpack.config.main.prod.js similarity index 85% rename from webpack.config.main.prod.js rename to internals/webpack/webpack.config.main.prod.js index f6e9a55e..2213362d 100644 --- a/webpack.config.main.prod.js +++ b/internals/webpack/webpack.config.main.prod.js @@ -2,10 +2,11 @@ * Webpack config for production electron main process */ +import path from 'path' import webpack from 'webpack' import merge from 'webpack-merge' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' -import baseConfig from './webpack.config.base' +import baseConfig, { rootDir } from './webpack.config.base' export default merge.smart(baseConfig, { devtool: 'source-map', @@ -14,12 +15,12 @@ export default merge.smart(baseConfig, { mode: 'production', - entry: './app/main.dev', + entry: path.join(rootDir, 'app', 'main.dev'), // 'main.js' in root output: { - path: __dirname, - filename: './app/main.prod.js' + path: path.join(rootDir, 'app'), + filename: 'main.prod.js' }, plugins: [ diff --git a/webpack.config.renderer.dev.dll.js b/internals/webpack/webpack.config.renderer.dev.dll.js similarity index 90% rename from webpack.config.renderer.dev.dll.js rename to internals/webpack/webpack.config.renderer.dev.dll.js index dd7c0bbf..cb0748a6 100644 --- a/webpack.config.renderer.dev.dll.js +++ b/internals/webpack/webpack.config.renderer.dev.dll.js @@ -5,10 +5,8 @@ import webpack from 'webpack' import path from 'path' import merge from 'webpack-merge' -import baseConfig from './webpack.config.base' -import { dependencies } from './package.json' - -const dist = path.resolve(process.cwd(), 'dll') +import baseConfig, { rootDir } from './webpack.config.base' +import { dependencies } from '../../package.json' export default merge.smart(baseConfig, { context: process.cwd(), @@ -74,7 +72,7 @@ export default merge.smart(baseConfig, { { loader: 'sass-loader', options: { - includePaths: [path.join(__dirname, 'app')] + includePaths: ['app'] } } ] @@ -98,7 +96,7 @@ export default merge.smart(baseConfig, { { loader: 'sass-loader', options: { - includePaths: [path.join(__dirname, 'app')] + includePaths: ['app'] } } ] @@ -169,24 +167,24 @@ export default merge.smart(baseConfig, { }, output: { + path: path.join(rootDir, 'dll'), library: 'renderer', - path: dist, filename: '[name].dev.dll.js', libraryTarget: 'var' }, plugins: [ new webpack.DllPlugin({ - path: path.join(dist, '[name].json'), + path: path.join('dll', '[name].json'), name: '[name]' }), new webpack.LoaderOptionsPlugin({ debug: true, options: { - context: path.resolve(process.cwd(), 'app'), + context: path.join(rootDir, 'app'), output: { - path: path.resolve(process.cwd(), 'dll') + path: path.join(rootDir, 'dll') } } }) diff --git a/webpack.config.renderer.dev.js b/internals/webpack/webpack.config.renderer.dev.js similarity index 93% rename from webpack.config.renderer.dev.js rename to internals/webpack/webpack.config.renderer.dev.js index 8748f21e..a9b8691d 100644 --- a/webpack.config.renderer.dev.js +++ b/internals/webpack/webpack.config.renderer.dev.js @@ -19,12 +19,12 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin' import HtmlWebpackPlugin from 'html-webpack-plugin' import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin' import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin' -import baseConfig from './webpack.config.base' -import { mainLog } from './app/lib/utils/log' +import baseConfig, { rootDir } from './webpack.config.base' +import { mainLog } from '../../app/lib/utils/log' const port = process.env.PORT || 1212 const publicPath = `http://localhost:${port}/dist` -const dll = path.resolve(process.cwd(), 'dll') +const dll = path.resolve(rootDir, 'dll') const manifest = path.resolve(dll, 'renderer.json') /** @@ -44,7 +44,7 @@ export default merge.smart(baseConfig, { mode: 'development', - entry: ['webpack/hot/only-dev-server', path.join(__dirname, 'app/index.js')], + entry: ['webpack/hot/only-dev-server', path.join(rootDir, 'app', 'index.js')], output: { publicPath: `http://localhost:${port}/dist/` @@ -118,7 +118,7 @@ export default merge.smart(baseConfig, { loader: 'sass-loader', options: { sourceMap: true, - includePaths: [path.join(__dirname, 'app')] + includePaths: ['app'] } } ] @@ -143,7 +143,7 @@ export default merge.smart(baseConfig, { loader: 'sass-loader', options: { sourceMap: true, - includePaths: [path.join(__dirname, 'app')] + includePaths: ['app'] } } ] @@ -221,11 +221,11 @@ export default merge.smart(baseConfig, { }), new HtmlWebpackPlugin({ - template: path.join(__dirname, 'app', 'app.html') + template: path.join('app', 'app.html') }), new AddAssetHtmlPlugin({ - filepath: path.join(__dirname, 'dll', 'renderer.dev.dll.js'), + filepath: path.join('dll', 'renderer.dev.dll.js'), includeSourcemap: false }), @@ -266,7 +266,6 @@ export default merge.smart(baseConfig, { serve: { port, - content: path.join(__dirname, 'dist'), hotClient: { validTargets: ['electron-renderer'] }, diff --git a/webpack.config.renderer.prod.js b/internals/webpack/webpack.config.renderer.prod.js similarity index 94% rename from webpack.config.renderer.prod.js rename to internals/webpack/webpack.config.renderer.prod.js index be30afe8..e8120d8a 100644 --- a/webpack.config.renderer.prod.js +++ b/internals/webpack/webpack.config.renderer.prod.js @@ -9,7 +9,7 @@ import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' import CleanWebpackPlugin from 'clean-webpack-plugin' import merge from 'webpack-merge' -import baseConfig from './webpack.config.base' +import baseConfig, { rootDir } from './webpack.config.base' export default merge.smart(baseConfig, { devtool: 'source-map', @@ -18,10 +18,10 @@ export default merge.smart(baseConfig, { mode: 'production', - entry: './app/index', + entry: path.join(rootDir, 'app', 'index'), output: { - path: path.join(__dirname, 'app/dist'), + path: path.join(rootDir, 'app', 'dist'), publicPath: '../dist/', filename: 'renderer.prod.js' }, @@ -148,7 +148,7 @@ export default merge.smart(baseConfig, { }, plugins: [ - new CleanWebpackPlugin(['app/dist']), + new CleanWebpackPlugin([path.join('app', 'dist')]), new ExtractTextPlugin('style.css'), @@ -158,7 +158,7 @@ export default merge.smart(baseConfig, { }), new HtmlWebpackPlugin({ - template: path.join(__dirname, 'app', 'app.html') + template: path.join('app', 'app.html') }), new CspHtmlWebpackPlugin({ diff --git a/package.json b/package.json index cc97f9bc..9a2d1f1d 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "description": "desktop application for the lightning network", "scripts": { "build": "concurrently --raw \"npm:build-main\" \"npm:build-renderer\"", - "build-dll": "webpack --require babel-register --config webpack.config.renderer.dev.dll.js --progress", - "build-main": "webpack --require babel-register --config webpack.config.main.prod.js --progress", - "build-renderer": "webpack --require babel-register --config webpack.config.renderer.prod.js --progress", + "build-dll": "webpack --require babel-register --config internals/webpack/webpack.config.renderer.dev.dll.js --progress", + "build-main": "webpack --require babel-register --config internals/webpack/webpack.config.main.prod.js --progress", + "build-renderer": "webpack --require babel-register --config internals/webpack/webpack.config.renderer.prod.js --progress", "build-grpc": "rimraf app/node_modules/grpc/src/node && build install-app-deps", "clean": "rimraf node_modules app/node_modules dll app/dist coverage .eslintcache", "coverage": "open coverage/index.html", @@ -32,7 +32,7 @@ "prestart": "npm run build", "start": "cross-env NODE_ENV=production electron ./app/", "start-main-dev": "cross-env HOT=1 NODE_ENV=development electron -r babel-register ./app/main.dev", - "start-renderer-dev": "node --trace-warnings -r babel-register ./node_modules/webpack-serve/lib/cli.js --config webpack.config.renderer.dev.js", + "start-renderer-dev": "node --trace-warnings -r babel-register ./node_modules/webpack-serve/lib/cli.js --config internals/webpack/webpack.config.renderer.dev.js", "test": "npm run lint && npm run lint-styles && npm run flow && npm run build && npm run test-unit && npm run test-e2e", "test-base": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=true ELECTRON_DISABLE_SECURITY_WARNINGS=true node --trace-warnings ./node_modules/jest/bin/jest --detectOpenHandles", "test-unit": "npm run test-base -- ./test/unit", @@ -318,7 +318,7 @@ "untildify": "^3.0.3", "validator": "^10.7.1" }, - "main": "webpack.config.base.js", + "main": "internals/webpack/webpack.config.base.js", "directories": { "test": "test" }