Browse Source

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.
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
bf40af1ed7
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 2
      .eslintrc
  2. 20
      internals/webpack/webpack.config.base.js
  3. 0
      internals/webpack/webpack.config.eslint.js
  4. 9
      internals/webpack/webpack.config.main.prod.js
  5. 18
      internals/webpack/webpack.config.renderer.dev.dll.js
  6. 17
      internals/webpack/webpack.config.renderer.dev.js
  7. 10
      internals/webpack/webpack.config.renderer.prod.js
  8. 10
      package.json

2
.eslintrc

@ -75,7 +75,7 @@
"moduleDirectory": ["app", "app/node_modules", "node_modules"] "moduleDirectory": ["app", "app/node_modules", "node_modules"]
}, },
"webpack": { "webpack": {
"config": "webpack.config.eslint.js" "config": "internals/webpack/webpack.config.eslint.js"
} }
} }
} }

20
webpack.config.base.js → internals/webpack/webpack.config.base.js

@ -4,11 +4,20 @@
import path from 'path' import path from 'path'
import { IgnorePlugin } from 'webpack' 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 { export default {
externals: Object.keys(externals || {}), externals: Object.keys(externals || {}),
context: rootDir,
output: {
// https://github.com/webpack/webpack/issues/1114
libraryTarget: 'commonjs2'
},
module: { module: {
rules: [ 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. * Determine the array of extensions that should be used to resolve modules.
*/ */
resolve: { resolve: {
extensions: ['.js', '.jsx', '.json'], extensions: ['.js', '.jsx', '.json'],
modules: [path.join(__dirname, 'app'), 'node_modules'] modules: [path.join(rootDir, 'app'), 'node_modules']
}, },
plugins: [new IgnorePlugin(/^\.\/locale$/, /moment$/)], plugins: [new IgnorePlugin(/^\.\/locale$/, /moment$/)],

0
webpack.config.eslint.js → internals/webpack/webpack.config.eslint.js

9
webpack.config.main.prod.js → internals/webpack/webpack.config.main.prod.js

@ -2,10 +2,11 @@
* Webpack config for production electron main process * Webpack config for production electron main process
*/ */
import path from 'path'
import webpack from 'webpack' import webpack from 'webpack'
import merge from 'webpack-merge' import merge from 'webpack-merge'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import baseConfig from './webpack.config.base' import baseConfig, { rootDir } from './webpack.config.base'
export default merge.smart(baseConfig, { export default merge.smart(baseConfig, {
devtool: 'source-map', devtool: 'source-map',
@ -14,12 +15,12 @@ export default merge.smart(baseConfig, {
mode: 'production', mode: 'production',
entry: './app/main.dev', entry: path.join(rootDir, 'app', 'main.dev'),
// 'main.js' in root // 'main.js' in root
output: { output: {
path: __dirname, path: path.join(rootDir, 'app'),
filename: './app/main.prod.js' filename: 'main.prod.js'
}, },
plugins: [ plugins: [

18
webpack.config.renderer.dev.dll.js → internals/webpack/webpack.config.renderer.dev.dll.js

@ -5,10 +5,8 @@
import webpack from 'webpack' import webpack from 'webpack'
import path from 'path' import path from 'path'
import merge from 'webpack-merge' import merge from 'webpack-merge'
import baseConfig from './webpack.config.base' import baseConfig, { rootDir } from './webpack.config.base'
import { dependencies } from './package.json' import { dependencies } from '../../package.json'
const dist = path.resolve(process.cwd(), 'dll')
export default merge.smart(baseConfig, { export default merge.smart(baseConfig, {
context: process.cwd(), context: process.cwd(),
@ -74,7 +72,7 @@ export default merge.smart(baseConfig, {
{ {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
includePaths: [path.join(__dirname, 'app')] includePaths: ['app']
} }
} }
] ]
@ -98,7 +96,7 @@ export default merge.smart(baseConfig, {
{ {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
includePaths: [path.join(__dirname, 'app')] includePaths: ['app']
} }
} }
] ]
@ -169,24 +167,24 @@ export default merge.smart(baseConfig, {
}, },
output: { output: {
path: path.join(rootDir, 'dll'),
library: 'renderer', library: 'renderer',
path: dist,
filename: '[name].dev.dll.js', filename: '[name].dev.dll.js',
libraryTarget: 'var' libraryTarget: 'var'
}, },
plugins: [ plugins: [
new webpack.DllPlugin({ new webpack.DllPlugin({
path: path.join(dist, '[name].json'), path: path.join('dll', '[name].json'),
name: '[name]' name: '[name]'
}), }),
new webpack.LoaderOptionsPlugin({ new webpack.LoaderOptionsPlugin({
debug: true, debug: true,
options: { options: {
context: path.resolve(process.cwd(), 'app'), context: path.join(rootDir, 'app'),
output: { output: {
path: path.resolve(process.cwd(), 'dll') path: path.join(rootDir, 'dll')
} }
} }
}) })

17
webpack.config.renderer.dev.js → 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 HtmlWebpackPlugin from 'html-webpack-plugin'
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin' import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin'
import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin' import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin'
import baseConfig from './webpack.config.base' import baseConfig, { rootDir } from './webpack.config.base'
import { mainLog } from './app/lib/utils/log' import { mainLog } from '../../app/lib/utils/log'
const port = process.env.PORT || 1212 const port = process.env.PORT || 1212
const publicPath = `http://localhost:${port}/dist` 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') const manifest = path.resolve(dll, 'renderer.json')
/** /**
@ -44,7 +44,7 @@ export default merge.smart(baseConfig, {
mode: 'development', 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: { output: {
publicPath: `http://localhost:${port}/dist/` publicPath: `http://localhost:${port}/dist/`
@ -118,7 +118,7 @@ export default merge.smart(baseConfig, {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
sourceMap: true, sourceMap: true,
includePaths: [path.join(__dirname, 'app')] includePaths: ['app']
} }
} }
] ]
@ -143,7 +143,7 @@ export default merge.smart(baseConfig, {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
sourceMap: true, sourceMap: true,
includePaths: [path.join(__dirname, 'app')] includePaths: ['app']
} }
} }
] ]
@ -221,11 +221,11 @@ export default merge.smart(baseConfig, {
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: path.join(__dirname, 'app', 'app.html') template: path.join('app', 'app.html')
}), }),
new AddAssetHtmlPlugin({ new AddAssetHtmlPlugin({
filepath: path.join(__dirname, 'dll', 'renderer.dev.dll.js'), filepath: path.join('dll', 'renderer.dev.dll.js'),
includeSourcemap: false includeSourcemap: false
}), }),
@ -266,7 +266,6 @@ export default merge.smart(baseConfig, {
serve: { serve: {
port, port,
content: path.join(__dirname, 'dist'),
hotClient: { hotClient: {
validTargets: ['electron-renderer'] validTargets: ['electron-renderer']
}, },

10
webpack.config.renderer.prod.js → 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 { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import CleanWebpackPlugin from 'clean-webpack-plugin' import CleanWebpackPlugin from 'clean-webpack-plugin'
import merge from 'webpack-merge' import merge from 'webpack-merge'
import baseConfig from './webpack.config.base' import baseConfig, { rootDir } from './webpack.config.base'
export default merge.smart(baseConfig, { export default merge.smart(baseConfig, {
devtool: 'source-map', devtool: 'source-map',
@ -18,10 +18,10 @@ export default merge.smart(baseConfig, {
mode: 'production', mode: 'production',
entry: './app/index', entry: path.join(rootDir, 'app', 'index'),
output: { output: {
path: path.join(__dirname, 'app/dist'), path: path.join(rootDir, 'app', 'dist'),
publicPath: '../dist/', publicPath: '../dist/',
filename: 'renderer.prod.js' filename: 'renderer.prod.js'
}, },
@ -148,7 +148,7 @@ export default merge.smart(baseConfig, {
}, },
plugins: [ plugins: [
new CleanWebpackPlugin(['app/dist']), new CleanWebpackPlugin([path.join('app', 'dist')]),
new ExtractTextPlugin('style.css'), new ExtractTextPlugin('style.css'),
@ -158,7 +158,7 @@ export default merge.smart(baseConfig, {
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: path.join(__dirname, 'app', 'app.html') template: path.join('app', 'app.html')
}), }),
new CspHtmlWebpackPlugin({ new CspHtmlWebpackPlugin({

10
package.json

@ -5,9 +5,9 @@
"description": "desktop application for the lightning network", "description": "desktop application for the lightning network",
"scripts": { "scripts": {
"build": "concurrently --raw \"npm:build-main\" \"npm:build-renderer\"", "build": "concurrently --raw \"npm:build-main\" \"npm:build-renderer\"",
"build-dll": "webpack --require babel-register --config webpack.config.renderer.dev.dll.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 webpack.config.main.prod.js --progress", "build-main": "webpack --require babel-register --config internals/webpack/webpack.config.main.prod.js --progress",
"build-renderer": "webpack --require babel-register --config webpack.config.renderer.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", "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", "clean": "rimraf node_modules app/node_modules dll app/dist coverage .eslintcache",
"coverage": "open coverage/index.html", "coverage": "open coverage/index.html",
@ -32,7 +32,7 @@
"prestart": "npm run build", "prestart": "npm run build",
"start": "cross-env NODE_ENV=production electron ./app/", "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-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": "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-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", "test-unit": "npm run test-base -- ./test/unit",
@ -318,7 +318,7 @@
"untildify": "^3.0.3", "untildify": "^3.0.3",
"validator": "^10.7.1" "validator": "^10.7.1"
}, },
"main": "webpack.config.base.js", "main": "internals/webpack/webpack.config.base.js",
"directories": { "directories": {
"test": "test" "test": "test"
} }

Loading…
Cancel
Save