Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webpack): Add webpack-dev-server, add yarn.lock #22

Merged
merged 5 commits into from Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
dist/index.html
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -30,6 +30,7 @@ npm install
- `npm t`: Run test suite
- `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)
- `npm run test:prod`: Run linting + generate coverage
- `npm run dev`: Run a server at `localhost:8081` (default) for quick development
- `npm run build`: Bundles code, create docs and generate typings
- `npm run build:dev`: Same than `build`, but code is not minified
- `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)
Expand Down
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -16,7 +16,8 @@
"scripts": {
"lint": "tslint -e **/node_modules/** -e **/dist/** **/*.ts ",
"prebuild": "rimraf dist && rimraf docs",
"build": "webpack -p",
"dev": "webpack-dev-server",
"build": "cross-env NODE_ENV=production webpack -p",
"build:dev": "webpack",
"test": "jest",
"test:watch": "jest --watch",
Expand All @@ -30,6 +31,7 @@
"postinstall": "node tools/init"
},
"config": {
"devPort": "8081",
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
},
Expand Down Expand Up @@ -80,7 +82,9 @@
"colors": "^1.1.2",
"commitizen": "^2.9.5",
"coveralls": "^2.11.15",
"cross-env": "^3.2.3",
"cz-conventional-changelog": "^2.0.0",
"html-webpack-plugin": "^2.28.0",
"husky": "^0.13.1",
"jest": "^19.0.2",
"lodash": "^4.17.4",
Expand All @@ -96,6 +100,7 @@
"typedoc-webpack-plugin": "^1.1.3",
"typescript": "^2.1.6",
"validate-commit-msg": "^2.10.1",
"webpack": "^2.2.0"
"webpack": "^2.2.0",
"webpack-dev-server": "^2.4.1"
}
}
11 changes: 11 additions & 0 deletions template/index.html
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
</body>
</html>
67 changes: 52 additions & 15 deletions webpack.config.ts
@@ -1,15 +1,58 @@
import { join } from 'path'
import { join, resolve } from 'path'
const { camelCase } = require('lodash')
const webpack = require("webpack")
const { TsConfigPathsPlugin, CheckerPlugin } = require('awesome-typescript-loader')
const TypedocWebpackPlugin = require('typedoc-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const env = process && process.env && process.env.NODE_ENV
const serverPort = process.env.npm_package_config_devPort || 8081
const dev = !(env && env === 'production')

/**
* Update this variable if you change your library name
*/
const libraryName = '--libraryname--'
const plugins = [
new CheckerPlugin(),
new TsConfigPathsPlugin(),
new HtmlWebpackPlugin({
inject: true,
title: libraryName,
filename: 'index.html',
template: join(__dirname, 'template/index.html'),
hash: true,
chunks: ['common', 'index']
})
]

let entry: string | string[] = [
// 'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${serverPort}`,
// bundle the client for webpack-dev-servers and connect to the provided endpoint
'webpack/hot/only-dev-server',
// bundle the client for hot reloading
`./src/${libraryName}.ts`
]

if (dev === false) {
plugins.push(new TypedocWebpackPlugin(
{
theme: 'minimal',
out: 'docs',
target: 'es6',
ignoreCompilerErrors: true
},
'src'
))
entry = join(__dirname, `src/${libraryName}.ts`)
} else {
plugins.push(new webpack.HotModuleReplacementPlugin())
}

export default {
entry: join(__dirname, `src/${libraryName}.ts`),
entry: {
index: entry
},
// Currently cheap-module-source-map is broken https://github.com/webpack/webpack/issues/4176
devtool: 'source-map',
output: {
Expand All @@ -33,17 +76,11 @@ export default {
}
]
},
plugins: [
new CheckerPlugin(),
new TsConfigPathsPlugin(),
new TypedocWebpackPlugin(
{
theme: 'minimal',
out: 'docs',
target: 'es6',
ignoreCompilerErrors: true
},
'src'
)
]
plugins: plugins,
devServer: {
hot: true,
contentBase: resolve(__dirname, 'dist'),
port: serverPort,
publicPath: '/'
}
}