Skip to content

Commit 4cadd5c

Browse files
committed
feat(configurations): Simplify the web pack configuration using a single file. Add cross-env dependency
1 parent 9cdff82 commit 4cadd5c

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
- [x] [Typescript 2](https://blogs.msdn.microsoft.com/typescript/2016/07/11/announcing-typescript-2-0-beta/)
99
- [x] [Webpack Dashboard](https://github.com/FormidableLabs/webpack-dashboard)
1010
![Imgur](http://i.imgur.com/pETTX85.png)
11+
1112
# Getting started
1213

1314
## Clone Typescript Webpack Starter
15+
1416
```bash
1517
git clone https://github.com/emyann/typescript-webpack-starter.git
1618
cd typescript-webpack-starter
@@ -19,17 +21,25 @@ npm install
1921
```
2022

2123
## Run
22-
Run a Webpack dev server
24+
25+
Start a Webpack dev server
2326
```bash
2427
npm start
2528
```
2629

30+
Start a Webpack server with the production configuration
31+
```bash
32+
npm run server:prod
33+
```
34+
35+
2736
## Build Only
2837
Build a development release
2938
```bash
3039
npm run build
3140
```
3241

42+
3343
Build a production release
3444
```bash
3545
npm run build:prod

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
"description": "A damn simple starter for Typescript and Webpack",
55
"main": "src/index.ts",
66
"scripts": {
7-
"rimraf": "rimraf",
8-
"webpack": "webpack",
9-
"webpack-dev-server": "webpack-dev-server",
10-
"start": "npm run start:dev",
11-
"start:dev": "webpack-dashboard -- webpack-dev-server --config config/webpack/webpack.dev.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
7+
"start": "npm run server:dev",
8+
"server": "npm run server:dev",
9+
"server:dev": "webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
10+
"server:prod": "cross-env NODE_ENV=production webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
1211
"build": "npm run build:dev",
13-
"prebuild:dev": "npm run rimraf -- dist",
14-
"build:dev": "webpack --config config/webpack/webpack.dev.js --progress --profile --color --display-error-details --display-cached",
15-
"prebuild:prod": "npm run rimraf -- dist",
16-
"build:prod": "webpack --config config/webpack/webpack.prod.js --progress --profile --color --display-error-details --display-cached --bail",
12+
"build:dev": "webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached",
13+
"build:prod": "cross-env NODE_ENV=production webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached --bail",
14+
"clean": "npm cache clear && rimraf -- dist",
1715
"test": "echo \"Error: no test specified\" && exit 1"
1816
},
1917
"repository": {
@@ -24,6 +22,7 @@
2422
"license": "ISC",
2523
"devDependencies": {
2624
"@types/lodash": "^4.14.50",
25+
"cross-env": "^3.1.4",
2726
"css-loader": "^0.26.1",
2827
"ejs-loader": "^0.3.0",
2928
"eslint": "^3.14.0",

webpack.config.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
const DashboardPlugin = require('webpack-dashboard/plugin');
5+
const nodeEnv = process.env.NODE_ENV || 'development';
6+
const isProd = nodeEnv === 'production';
7+
8+
var config = {
9+
devtool: isProd ? 'hidden-source-map' : 'cheap-eval-source-map',
10+
context: path.resolve('./src'),
11+
entry: {
12+
app: './index.ts',
13+
vendor: './vendor.ts'
14+
},
15+
output: {
16+
path: path.resolve('./dist'),
17+
filename: '[name].bundle.js',
18+
sourceMapFilename: '[name].map',
19+
devtoolModuleFilenameTemplate: function (info) {
20+
return "file:///" + info.absoluteResourcePath;
21+
}
22+
},
23+
module: {
24+
rules: [
25+
{ enforce: 'pre', test: /\.ts$/, exclude: ["node_modules"], loader: 'ts-loader' },
26+
{ test: /\.html$/, loader: "html" },
27+
{ test: /\.css$/, loaders: ['style', 'css'] }
28+
]
29+
},
30+
resolve: {
31+
extensions: [".ts", ".js"],
32+
modules: [path.resolve('./src'), 'node_modules']
33+
},
34+
plugins: [
35+
new webpack.DefinePlugin({
36+
'process.env': { // eslint-disable-line quote-props
37+
NODE_ENV: JSON.stringify(nodeEnv)
38+
}
39+
}),
40+
new HtmlWebpackPlugin({
41+
title: 'Typescript Webpack Starter',
42+
template: '!!ejs-loader!src/index.html'
43+
}),
44+
new webpack.optimize.CommonsChunkPlugin({
45+
name: 'vendor',
46+
minChunks: Infinity,
47+
filename: 'vendor.bundle.js'
48+
}),
49+
new webpack.optimize.UglifyJsPlugin({
50+
compress: { warnings: false },
51+
output: { comments: false },
52+
sourceMap: false
53+
}),
54+
new DashboardPlugin(),
55+
new webpack.LoaderOptionsPlugin({
56+
options: {
57+
tslint: {
58+
emitErrors: true,
59+
failOnHint: true
60+
}
61+
}
62+
})
63+
]
64+
};
65+
66+
module.exports = config;

0 commit comments

Comments
 (0)