Skip to content

Commit 525c35c

Browse files
committed
[chore] moving webpack scripts to scripts folder.
1 parent aa822be commit 525c35c

10 files changed

+93
-127
lines changed

Makefile

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
NODE=$(shell which node)
2-
NPM=$(shell which npm)
3-
YARN=$(shell which yarn)
4-
JQ=$(shell which jq)
1+
NODE=$(shell which node 2> /dev/null)
2+
NPM=$(shell which npm 2> /dev/null)
3+
YARN=$(shell which yarn 2> /dev/null)
4+
JQ=$(shell which jq 2> /dev/null)
5+
6+
PKM?=$(if $(YARN),$(YARN),$(shell which npm))
57

68
BABEL=./node_modules/.bin/babel
79
COVERALLS=./node_modules/coveralls/bin/coveralls.js
@@ -29,10 +31,9 @@ help: info
2931
@echo " make publish-all - publish version and docs."
3032

3133
info:
32-
@echo node version: `$(NODE) --version` "($(NODE))"
33-
@echo npm version: `$(NPM) --version` "($(NPM))"
34-
@echo yarn version: `$(YARN) --version` "($(YARN))"
35-
@echo jq version: `$(JQ) --version` "($(JQ))"
34+
@[[ ! -z "$(NODE)" ]] && echo node version: `$(NODE) --version` "$(NODE)"
35+
@[[ ! -z "$(PKM)" ]] && echo $(shell basename $(PKM)) version: `$(PKM) --version` "$(PKM)"
36+
@[[ ! -z "$(JQ)" ]] && echo jq version: `$(JQ) --version` "$(JQ)"
3637

3738
deps: deps-project deps-docs
3839

@@ -54,7 +55,7 @@ tests-single-run:
5455
@npm run test -- --single-run
5556

5657
coveralls:
57-
-cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js 2>/dev/null
58+
-cat ./coverage/lcov.info | $(COVERALLS) 2>/dev/null
5859

5960
tests-ci: clean lint
6061
@COVERAGE=$(COVERAGE) make tests-single-run coveralls
@@ -91,7 +92,7 @@ compile:
9192

9293
build: compile
9394
@echo "[Building dists]"
94-
@./node_modules/.bin/webpack --config webpack.dist.config.js
95+
@./node_modules/.bin/webpack --config ./scripts/webpack.dist.config.js
9596

9697
release-commit:
9798
git commit --allow-empty -m "Release v`cat .version`."

bootstrap.sh

-36
This file was deleted.

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function(config) {
1818

1919
files: ['./specs/index.js'],
2020

21-
webpack: require('./webpack.test.config'),
21+
webpack: require('./scripts/webpack.test.config'),
2222

2323
webpackMiddleware: { stats: 'errors-only' },
2424

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"example": "examples"
1515
},
1616
"scripts": {
17-
"start": "./node_modules/.bin/webpack-dev-server --inline --host 127.0.0.1 --content-base examples/",
17+
"start": "npx webpack-dev-server --config ./scripts/webpack.config.js --inline --host 127.0.0.1 --content-base examples/",
1818
"test": "cross-env NODE_ENV=test karma start",
1919
"lint": "eslint src/ specs/"
2020
},

scripts/defaultConfig.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
mode: 'development',
5+
output: {
6+
filename: '[name].js',
7+
path: path.resolve(__dirname, './examples/__build__'),
8+
publicPath: '/__build__/'
9+
},
10+
module: {
11+
rules: [
12+
{ test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader' } }
13+
]
14+
},
15+
resolve: {
16+
alias: {
17+
"react-modal": path.resolve(__dirname, "../src")
18+
}
19+
}
20+
};

scripts/webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const webpack = require('webpack');
4+
const defaultConfig = require('./defaultConfig');
5+
6+
var EXAMPLES_DIR = path.resolve(__dirname, '../examples');
7+
8+
function isDirectory(dir) {
9+
return fs.lstatSync(dir).isDirectory();
10+
}
11+
12+
function buildEntries() {
13+
return fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) {
14+
if (dir === 'build')
15+
return entries;
16+
17+
var isDraft = dir.charAt(0) === '_';
18+
19+
if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir)))
20+
entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js');
21+
22+
return entries;
23+
}, {});
24+
}
25+
26+
module.exports = {
27+
...defaultConfig,
28+
entry: buildEntries(),
29+
};
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,45 @@
1-
var webpack = require('webpack');
2-
var path = require('path');
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const defaultConfig = require('./defaultConfig');
34

4-
var reactExternal = {
5+
const reactExternal = {
56
root: 'React',
67
commonjs2: 'react',
78
commonjs: 'react',
89
amd: 'react'
910
};
10-
var reactDOMExternal = {
11+
const reactDOMExternal = {
1112
root: 'ReactDOM',
1213
commonjs2: 'react-dom',
1314
commonjs: 'react-dom',
1415
amd: 'react-dom'
1516
};
1617

1718
module.exports = {
19+
...defaultConfig,
1820
mode: 'production',
19-
2021
entry: {
21-
'react-modal': './src/index.js',
22-
'react-modal.min': './src/index.js'
22+
'react-modal': path.resolve(__dirname, '../src/index.js'),
23+
'react-modal.min': path.resolve(__dirname, '../src/index.js')
2324
},
24-
2525
externals: {
2626
'react': reactExternal,
2727
'react-dom': reactDOMExternal
2828
},
29-
3029
output: {
3130
filename: '[name].js',
3231
chunkFilename: '[id].chunk.js',
33-
path: path.resolve(__dirname, 'dist'),
32+
path: path.resolve(__dirname, '../dist'),
3433
publicPath: '/',
3534
libraryTarget: 'umd',
3635
library: 'ReactModal'
3736
},
38-
3937
optimization: {
4038
minimize: true
4139
},
42-
4340
plugins: [
4441
new webpack.DefinePlugin({
4542
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
4643
})
47-
],
48-
49-
module: {
50-
rules: [
51-
{ test: /\.js?$/, exclude: /node_modules/, use: { loader: 'babel-loader' } }
52-
]
53-
}
54-
44+
]
5545
};

scripts/webpack.test.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require('path');
2+
const defaultConfig = require('./defaultConfig');
3+
4+
module.exports = {
5+
...defaultConfig,
6+
plugins: [],
7+
entry: path.resolve(__dirname, '../specs/index.js'),
8+
devtool: 'inline-source-map',
9+
module: {
10+
...defaultConfig.module,
11+
rules: [
12+
{
13+
test: /\.js$/,
14+
use: { loader: 'istanbul-instrumenter-loader' },
15+
enforce: 'post',
16+
include: path.resolve(__dirname, '../src')
17+
},
18+
...defaultConfig.module.rules
19+
]
20+
}
21+
};

webpack.config.js

-43
This file was deleted.

webpack.test.config.js

-16
This file was deleted.

0 commit comments

Comments
 (0)