Skip to content

Commit

Permalink
[chore] moving webpack scripts to scripts folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
diasbruno committed Dec 9, 2019
1 parent aa822be commit 525c35c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 127 deletions.
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
NODE=$(shell which node)
NPM=$(shell which npm)
YARN=$(shell which yarn)
JQ=$(shell which jq)
NODE=$(shell which node 2> /dev/null)
NPM=$(shell which npm 2> /dev/null)
YARN=$(shell which yarn 2> /dev/null)
JQ=$(shell which jq 2> /dev/null)

PKM?=$(if $(YARN),$(YARN),$(shell which npm))

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

info:
@echo node version: `$(NODE) --version` "($(NODE))"
@echo npm version: `$(NPM) --version` "($(NPM))"
@echo yarn version: `$(YARN) --version` "($(YARN))"
@echo jq version: `$(JQ) --version` "($(JQ))"
@[[ ! -z "$(NODE)" ]] && echo node version: `$(NODE) --version` "$(NODE)"
@[[ ! -z "$(PKM)" ]] && echo $(shell basename $(PKM)) version: `$(PKM) --version` "$(PKM)"
@[[ ! -z "$(JQ)" ]] && echo jq version: `$(JQ) --version` "$(JQ)"

deps: deps-project deps-docs

Expand All @@ -54,7 +55,7 @@ tests-single-run:
@npm run test -- --single-run

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

tests-ci: clean lint
@COVERAGE=$(COVERAGE) make tests-single-run coveralls
Expand Down Expand Up @@ -91,7 +92,7 @@ compile:

build: compile
@echo "[Building dists]"
@./node_modules/.bin/webpack --config webpack.dist.config.js
@./node_modules/.bin/webpack --config ./scripts/webpack.dist.config.js

release-commit:
git commit --allow-empty -m "Release v`cat .version`."
Expand Down
36 changes: 0 additions & 36 deletions bootstrap.sh

This file was deleted.

2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(config) {

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

webpack: require('./webpack.test.config'),
webpack: require('./scripts/webpack.test.config'),

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"example": "examples"
},
"scripts": {
"start": "./node_modules/.bin/webpack-dev-server --inline --host 127.0.0.1 --content-base examples/",
"start": "npx webpack-dev-server --config ./scripts/webpack.config.js --inline --host 127.0.0.1 --content-base examples/",
"test": "cross-env NODE_ENV=test karma start",
"lint": "eslint src/ specs/"
},
Expand Down
20 changes: 20 additions & 0 deletions scripts/defaultConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require('path');

module.exports = {
mode: 'development',
output: {
filename: '[name].js',
path: path.resolve(__dirname, './examples/__build__'),
publicPath: '/__build__/'
},
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader' } }
]
},
resolve: {
alias: {
"react-modal": path.resolve(__dirname, "../src")
}
}
};
29 changes: 29 additions & 0 deletions scripts/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const defaultConfig = require('./defaultConfig');

var EXAMPLES_DIR = path.resolve(__dirname, '../examples');

function isDirectory(dir) {
return fs.lstatSync(dir).isDirectory();
}

function buildEntries() {
return fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) {
if (dir === 'build')
return entries;

var isDraft = dir.charAt(0) === '_';

if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir)))
entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js');

return entries;
}, {});
}

module.exports = {
...defaultConfig,
entry: buildEntries(),
};
30 changes: 10 additions & 20 deletions webpack.dist.config.js → scripts/webpack.dist.config.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
var webpack = require('webpack');
var path = require('path');
const webpack = require('webpack');
const path = require('path');
const defaultConfig = require('./defaultConfig');

var reactExternal = {
const reactExternal = {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
};
var reactDOMExternal = {
const reactDOMExternal = {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
};

module.exports = {
...defaultConfig,
mode: 'production',

entry: {
'react-modal': './src/index.js',
'react-modal.min': './src/index.js'
'react-modal': path.resolve(__dirname, '../src/index.js'),
'react-modal.min': path.resolve(__dirname, '../src/index.js')
},

externals: {
'react': reactExternal,
'react-dom': reactDOMExternal
},

output: {
filename: '[name].js',
chunkFilename: '[id].chunk.js',
path: path.resolve(__dirname, 'dist'),
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
libraryTarget: 'umd',
library: 'ReactModal'
},

optimization: {
minimize: true
},

plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
],

module: {
rules: [
{ test: /\.js?$/, exclude: /node_modules/, use: { loader: 'babel-loader' } }
]
}

]
};
21 changes: 21 additions & 0 deletions scripts/webpack.test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');
const defaultConfig = require('./defaultConfig');

module.exports = {
...defaultConfig,
plugins: [],
entry: path.resolve(__dirname, '../specs/index.js'),
devtool: 'inline-source-map',
module: {
...defaultConfig.module,
rules: [
{
test: /\.js$/,
use: { loader: 'istanbul-instrumenter-loader' },
enforce: 'post',
include: path.resolve(__dirname, '../src')
},
...defaultConfig.module.rules
]
}
};
43 changes: 0 additions & 43 deletions webpack.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions webpack.test.config.js

This file was deleted.

0 comments on commit 525c35c

Please sign in to comment.