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 2 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 README.md
Original file line number Diff line number Diff line change
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
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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 --port 8081",
"build": "cross-env NODE_ENV=production webpack -p",
"build:dev": "webpack",
"test": "jest",
"test:watch": "jest --watch",
Expand Down Expand Up @@ -80,7 +81,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 +99,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 src/template/common.html
Original file line number Diff line number Diff line change
@@ -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>
66 changes: 50 additions & 16 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
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 dev = !(env && env === 'production')
/**
* Update this variable if you change your library name
*/
const libraryName = '--libraryname--'
const plugins = [
new CheckerPlugin(),
new webpack.HotModuleReplacementPlugin(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we don't need the Hot Module replacement when building for production. Can you make it only for development?

new TsConfigPathsPlugin(),
new HtmlWebpackPlugin({
inject: true,
title: libraryName,
filename: 'index.html',
template: join(__dirname, 'src/template/common.html'),
hash: true,
chunks: ['common', 'index']
})
]
let entry: string | string[] = [
// 'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8081',
// bundle the client for webpack-dev-servers
// and connect to the provided endpoint
'webpack/hot/only-dev-server',
// bundle the client for hot reloading
// only- means to only hot reload for successful updates
`./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`)
}

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 +74,10 @@ 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'),
publicPath: '/'
}
}