Skip to content

Commit

Permalink
created examples, updated read me, fixed configuration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Dabrowski authored and Andrew Dabrowski committed Oct 16, 2017
1 parent 519e49a commit b679300
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 31 deletions.
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ coverage

# Tests
jest.config.json
tests
tests

# TypeScript
tsconfig.json
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# webpack-ts-build
Webpack Build

[![Build Status](https://travis-ci.org/afdabro/webpack-ts-build.svg?branch=master)](https://travis-ci.org/afdabro/webpack-ts-build)

[![Coverage Status](https://coveralls.io/repos/github/afdabro/webpack-ts-build/badge.svg?branch=master)](https://coveralls.io/github/afdabro/webpack-ts-build?branch=master)

## Purpose
Simplify the configuration and building of Typescript, Webpack, React, etc. etc.

## FAQ

### Where can I find a simple example of how to use the build package?
The [Examples](https://github.com/afdabro/webpack-ts-build/tree/master/examples) page covers how to configure a default webpack, setup a build, and use the development server.

### Why is the code coverage so low?
Well, a majority of the code is configuration-driven which does not lend itself well to unit tests.
5 changes: 5 additions & 0 deletions examples/build.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const config = require('./webpack.example');
const buildProd = require('../index').buildProd;

buildProd(config);
5 changes: 5 additions & 0 deletions examples/devserver.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const config = require('./webpack.example');
const devServer = require('../index').devServer;

devServer(config, './bin');
6 changes: 6 additions & 0 deletions examples/src/appLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as React from "react";
import * as ReactDOM from "react-dom";

ReactDOM.render(
<div>Hello React</div>,
document.getElementById("root"));
Binary file added examples/src/assets/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<div id="root"></div>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/webpack.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const defaultWebpack = require('../index').defaultWebpack;

/*
Paths
*/
const path = require('path');
const buildPath = path.join(__dirname, './bin');
const sourcePath = path.join(__dirname, './src');
const domainHost = '';

module.exports = (isDev) => {
const appPlugins = [];

const options = {
'isDev': isDev,
'faviconPath': 'assets/favicon.ico',
'domainHost': domainHost,
'sourcePath': sourcePath,
'appLoader': './appLoader',
'buildPath': buildPath,
'appPlugins': appPlugins,
};

return defaultWebpack(options);
};
28 changes: 16 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// TODO: describe
/*
'use strict';

const Classes = Object.create(null);

const options = {
'isDev': isDev,
'isDev': true,
'faviconPath': 'assets/favicon.ico',
'domainHost': domainHost,
'sourcePath': sourcePath,
'domainHost': '',
'sourcePath': '',
'appLoader': './appLoader',
'buildPath': buildPath,
'appPlugins': appPlugins
};*/
'buildPath': '',
'appPlugins': [],
};

module.exports.options = options;

/**
* Generates a default webpack configuration based on the options provided.
* @param {object} options - configuration options.
* @param {options} options - configuration options.
* @return {object} default webpack configuration
*/
module.exports = function defaultWebpack(options) {
module.exports.defaultWebpack = function defaultWebpack(options) {
const defaultWebpack = loadClass('default.webpack');
return defaultWebpack(options);
};
Expand All @@ -24,7 +28,7 @@ module.exports = function defaultWebpack(options) {
* Executes a production build using the webpack configuration.
* @param {object} webpackConfig - webpack configuratin.
*/
module.exports = function buildProd(webpackConfig) {
module.exports.buildProd = function buildProd(webpackConfig) {
const buildProd = loadClass('build.prod');
buildProd(webpackConfig);
};
Expand All @@ -34,7 +38,7 @@ module.exports = function buildProd(webpackConfig) {
* @param {object} webpackConfig - webpack configuratin.
* @param {string} contentBase - base content path.
*/
module.exports = function devServer(webpackConfig, contentBase) {
module.exports.devServer = function devServer(webpackConfig, contentBase) {
const devServer = loadClass('dev.server');
devServer(webpackConfig, contentBase);
};
Expand Down
28 changes: 14 additions & 14 deletions lib/default.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ exports.getDefaultPlugins = (isDev, faviconPath, domainHost) => {
webpackFilter.ifProd(new WebpackMd5Hash()),
extractSass,
webpackFilter.ifProd(new UglifyJsPlugin({
'mangle': true,
'warnings': false,
'screw_ie8': true,
'conditionals': true,
'unused': true,
'comparisons': true,
'sourceMap': true,
'sequences': true,
'dead_code': true,
'evaluate': true,
'if_return': true,
'join_vars': true,
'output': {
comments: false,
'uglifyOptions': {
'mangle': true,
'warnings': false,
'ecma': 6,
'compress': {
'conditionals': true,
'unused': true,
'comparisons': true,
'dead_code': true,
'evaluate': true,
'if_return': true,
'join_vars': true,
},
'sourceMap': true,
},
})),
new HtmlWebpackPlugin({
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "0.0.1",
"description": "webpack build tools for typescript",
"scripts": {
"lint" : "eslint lib/**",
"build-example": "node examples/build.example.js",
"devserver-example": "node examples/devserver.example.js",
"lint": "eslint lib/**",
"test": "jest --config jest.config.json",
"test-ci": "jest --config jest.config.json --coverage"
},
Expand All @@ -14,7 +16,9 @@
"coveralls": "^3.0.0",
"eslint": "^4.8.0",
"eslint-config-google": "^0.9.1",
"jest": "^21.2.1"
"jest": "^21.2.1",
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"dependencies": {
"autoprefixer": "^7.1.5",
Expand Down
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"baseUrl": "source",
"alwaysStrict": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./bin/",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"jsx": "react",
"allowJs": true
},
"exclude": [
"node_modules",
"bin"
]
}
22 changes: 20 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"

loose-envify@^1.0.0, loose-envify@^1.3.1:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
Expand Down Expand Up @@ -4459,7 +4459,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.4:
prop-types@^15.5.4, prop-types@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856"
dependencies:
Expand Down Expand Up @@ -4597,6 +4597,15 @@ react-deep-force-update@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.1.1.tgz#8ea4263cd6455a050b37445b3f08fd839d86e909"

react-dom@^16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.0.0.tgz#9cc3079c3dcd70d4c6e01b84aab2a7e34c303f58"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"

react-hot-loader@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-3.0.0.tgz#6e28da9d459da8085f5ee8bdd775046ba4b5cd0b"
Expand All @@ -4614,6 +4623,15 @@ react-proxy@^3.0.0-alpha.0:
dependencies:
lodash "^4.6.1"

react@^16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.0.0.tgz#ce7df8f1941b036f02b2cca9dbd0cb1f0e855e2d"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"

read-pkg-up@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
Expand Down

0 comments on commit b679300

Please sign in to comment.