Skip to content

Commit db8113f

Browse files
committed
feat(eslint): use the root eslint config in webpack
1 parent c95f95c commit db8113f

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config.isDev = process.env.NODE_ENV === 'development'
1616
config.PORT = Number(process.env.PORT) || Number(flags['--port']) || 80
1717
config.PIXORE_PATH = config.isProd ? (mainPackage.pixorePath || '') : ''
1818
config.ROOT_PATH = appRoot
19+
config.ESLINT_PATH = path.join(config.ROOT_PATH, '.eslintrc.js')
1920
config.BUILD_PATH = path.join(config.ROOT_PATH, 'build')
2021
config.SRC_PATH = path.join(config.ROOT_PATH, 'src')
2122
config.APP_PATH = path.join(config.SRC_PATH, 'index.js')

src/config/webpack.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const path = require('path')
2+
const assign = require('lodash.assign')
23
const debug = require('debug')('pixore')
34
const webpack = require('webpack')
45
const HtmlWebpackPlugin = require('html-webpack-plugin')
56
const UglifyJSPlugin = require('html-webpack-plugin')
67
const ExtractTextPlugin = require('extract-text-webpack-plugin')
78
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
8-
const { isProd, MAIN_TEMPLATE, APP_PATH, BUILD_PATH, PIXORE_PATH, ROOT_PATH } = require('./environment')
9+
const { isProd, MAIN_TEMPLATE, APP_PATH, BUILD_PATH, PIXORE_PATH, ROOT_PATH, ESLINT_PATH } = require('./environment')
910

1011
debug.namespace = ''
1112

@@ -26,9 +27,9 @@ const modules = {
2627
loader: 'eslint-loader',
2728
enforce: 'pre',
2829
exclude: /node_modules|webpackHotDevClient/,
29-
options: {
30+
options: assign({
3031
cacheDirectory: true
31-
}
32+
}, require(ESLINT_PATH))
3233
}, {
3334
test: /\.js$/,
3435
exclude: /node_modules/,

src/utils.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ const debugError = require('debug')('pixore:error')
66
const chalk = require('chalk')
77
const webpack = require('webpack')
88
const assign = require('lodash.assign')
9-
const appRoot = fs.realpathSync(process.cwd())
109
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
1110

1211
debug.namespace = ''
1312

1413
debugError.color = require('debug').colors[5]
1514

16-
const { APP_PATH, ROOT_PATH, MAIN_TEMPLATE } = require('./config/environment')
15+
const { APP_PATH, ROOT_PATH, MAIN_TEMPLATE, ESLINT_PATH } = require('./config/environment')
1716
const config = require('./config/webpack.config.js')
1817

1918
let customConfig = {}
20-
if (fs.existsSync(path.join(appRoot, 'webpack.config.js'))) {
21-
customConfig = require(path.join(appRoot, 'webpack.config.js'))
19+
if (fs.existsSync(path.join(ROOT_PATH, 'webpack.config.js'))) {
20+
customConfig = require(path.join(ROOT_PATH, 'webpack.config.js'))
2221
}
2322

24-
const eslintFilePath = path.join(appRoot, '.eslintrc.js')
25-
2623
exports.setupCompile = () => {
2724
const compiler = webpack(assign(config, customConfig))
2825

@@ -64,8 +61,8 @@ exports.validStructure = () => {
6461
debugError(APP_PATH.replace(ROOT_PATH, '') + ' doesn\'t exists')
6562
process.exit(1)
6663
}
67-
if (!fs.existsSync(eslintFilePath)) {
68-
debugError(eslintFilePath.replace(ROOT_PATH, '') + ' doesn\'t exists')
64+
if (!fs.existsSync(ESLINT_PATH)) {
65+
debugError(ESLINT_PATH.replace(ROOT_PATH, '') + ' doesn\'t exists')
6966
process.exit(1)
7067
}
7168
if (!fs.existsSync(MAIN_TEMPLATE)) {

0 commit comments

Comments
 (0)