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"]
},
"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 { 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$/)],

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
*/
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: [

18
webpack.config.renderer.dev.dll.js → 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')
}
}
})

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 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']
},

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 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({

10
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"
}

Loading…
Cancel
Save