Skip to content

Commit 134e64b

Browse files
committed
Converted webpack config to TS and updated webpack to 3.4
1 parent b0d156c commit 134e64b

10 files changed

+243
-202
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
env/
33
node_modules/
4-
config.js
4+
config.dev.ts
5+
config.prod.ts
56
build/build.js
6-
build/awCache/
7+
.awCache/

config.example.js config.example.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Example config, rename to config.js.
2-
module.exports = {
2+
export default {
33
api: {
44
host: "localhost:8000",
55
key: "03f21b939e022176e87feb7704477bbc"
6-
}
6+
},
77
thunder: {
88
host: "localhost:8080",
99
key: "public123",

dev/webpack.dev.ts

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// tslint:disable:no-console
2+
import * as webpack from "webpack";
3+
import * as WebpackDevServer from "webpack-dev-server";
4+
import * as path from "path";
5+
import config from "../config.dev";
6+
7+
const port = 3000;
8+
const publicPath = "/";
9+
10+
new WebpackDevServer(webpack({
11+
target: "web",
12+
devtool: "#source-map",
13+
context: path.resolve(__dirname, "../"),
14+
entry: [
15+
"tslib",
16+
"webpack-dev-server/client?http://localhost:3000",
17+
"webpack/hot/only-dev-server",
18+
path.resolve("src/App")
19+
],
20+
output: {
21+
path: path.resolve("build"),
22+
filename: "build.js",
23+
publicPath
24+
},
25+
resolve: {
26+
extensions: [".css", ".scss", ".js", ".jsx", ".ts", ".tsx", ".json"],
27+
modules: [
28+
path.resolve("node_modules"),
29+
path.resolve("src")
30+
]
31+
},
32+
module: {
33+
rules: [{
34+
test: /\.tsx?$/,
35+
use: [
36+
"react-hot-loader",
37+
"awesome-typescript-loader"
38+
],
39+
exclude: /node_modules/
40+
}, {
41+
test: /\.s?css$/,
42+
use: [
43+
"style-loader",
44+
{
45+
loader: "typings-for-css-modules-loader",
46+
options: {
47+
modules: true,
48+
importLoaders: 1,
49+
localIdentName: "[name]_[local]_[hash:base64:5]",
50+
sass: true,
51+
namedExport: true,
52+
camelCase: true
53+
}
54+
},
55+
"postcss-loader",
56+
{
57+
loader: "sass-loader",
58+
options: {
59+
includePaths: [
60+
path.resolve("node_modules"),
61+
path.resolve("src")
62+
]
63+
}
64+
}
65+
]
66+
}, {
67+
test: /\.(jpe?g|gif|png|svg|woff|ttf|wav|mp3)$/,
68+
loader: "file-loader"
69+
}]
70+
},
71+
plugins: [
72+
new webpack.HotModuleReplacementPlugin(),
73+
new webpack.DefinePlugin({
74+
"process.env": {
75+
NODE_ENV: JSON.stringify("development")
76+
},
77+
"config": {
78+
API: JSON.stringify(config.api),
79+
THUNDER: JSON.stringify(config.thunder),
80+
SENTRY: JSON.stringify(config.sentry),
81+
SCREEN: JSON.stringify(process.env.SCREEN || "primary")
82+
},
83+
"__DEV__": true
84+
})
85+
]
86+
}), {
87+
publicPath,
88+
contentBase: "./build",
89+
hot: true,
90+
stats: {
91+
colors: true,
92+
hash: false,
93+
version: false,
94+
timings: true,
95+
assets: true,
96+
chunks: false,
97+
modules: false,
98+
reasons: false,
99+
children: false,
100+
source: false,
101+
errors: true,
102+
errorDetails: true,
103+
warnings: true,
104+
publicPath: false
105+
}
106+
}).listen(port, "0.0.0.0", (err, result) => {
107+
if (err) {
108+
console.log(err);
109+
}
110+
111+
console.log("Listening at http://localhost:" + port);
112+
});

dev/webpack.prod.ts

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// tslint:disable:no-console
2+
import * as webpack from "webpack";
3+
import * as path from "path";
4+
import config from "../config.prod";
5+
6+
const publicPath = "/";
7+
8+
webpack({
9+
target: "web",
10+
devtool: "#source-map",
11+
context: path.resolve(__dirname, "../"),
12+
entry: [
13+
"tslib",
14+
path.resolve("src/App")
15+
],
16+
output: {
17+
path: path.resolve("build"),
18+
filename: "build.js",
19+
publicPath
20+
},
21+
resolve: {
22+
extensions: [".css", ".scss", ".js", ".jsx", ".ts", ".tsx", ".json"],
23+
modules: [
24+
path.resolve("node_modules"),
25+
path.resolve("src")
26+
]
27+
},
28+
module: {
29+
rules: [{
30+
test: /\.tsx?$/,
31+
loader: "awesome-typescript-loader",
32+
exclude: /node_modules/
33+
}, {
34+
test: /\.s?css$/,
35+
use: [
36+
"style-loader",
37+
{
38+
loader: "typings-for-css-modules-loader",
39+
options: {
40+
modules: true,
41+
importLoaders: 1,
42+
localIdentName: "[name]_[local]_[hash:base64:5]",
43+
sass: true,
44+
namedExport: true,
45+
camelCase: true
46+
}
47+
},
48+
"postcss-loader",
49+
{
50+
loader: "sass-loader",
51+
options: {
52+
includePaths: [
53+
path.resolve("node_modules"),
54+
path.resolve("src")
55+
]
56+
}
57+
}
58+
]
59+
}, {
60+
test: /\.(jpe?g|gif|png|svg|woff|ttf|wav|mp3)$/,
61+
loader: "file-loader"
62+
}]
63+
},
64+
plugins: [
65+
new webpack.optimize.UglifyJsPlugin({
66+
compress: {
67+
warnings: false,
68+
drop_console: true
69+
}
70+
}),
71+
new webpack.DefinePlugin({
72+
"process.env": {
73+
NODE_ENV: JSON.stringify("production")
74+
},
75+
"config": {
76+
API: JSON.stringify(config.api),
77+
THUNDER: JSON.stringify(config.thunder),
78+
SENTRY: JSON.stringify(config.sentry),
79+
SCREEN: JSON.stringify(process.env.SCREEN || "primary")
80+
},
81+
"__DEV__": false
82+
})
83+
]
84+
}).run((err, stats) => {
85+
if (err) {
86+
console.log(err);
87+
}
88+
console.log(stats.toString({
89+
colors: true,
90+
hash: false,
91+
version: false,
92+
timings: true,
93+
assets: true,
94+
chunks: false,
95+
modules: false,
96+
reasons: false,
97+
children: false,
98+
source: false,
99+
errors: true,
100+
errorDetails: true,
101+
warnings: true,
102+
publicPath: false
103+
}));
104+
});

package.json

+18-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.1",
44
"description": "Foobar Kiosk application.",
55
"scripts": {
6-
"start": "node server.js",
7-
"build": "NODE_ENV=production webpack --progress --hide-modules --config webpack.prod.config.js",
6+
"start": "NODE_ENV=development node node_modules/ts-node/dist/bin ./dev/webpack.dev.ts",
7+
"build": "NODE_ENV=production node node_modules/ts-node/dist/bin ./dev/webpack.prod.ts",
88
"tslint": "node node_modules/tslint/bin/tslint --project tsconfig.json",
99
"precommit": "npm run tslint"
1010
},
@@ -17,7 +17,7 @@
1717
"url": "https://github.com/uppsaladatavetare/foobar-kiosk/issues"
1818
},
1919
"devDependencies": {
20-
"@types/classnames": "0.0.28",
20+
"@types/classnames": "2.2.0",
2121
"@types/isomorphic-fetch": "0.0.34",
2222
"@types/qrcode.react": "0.6.2",
2323
"@types/react": "15.6.1",
@@ -26,16 +26,18 @@
2626
"@types/react-redux": "4.4.47",
2727
"@types/redux-logger": "2.6.31",
2828
"@types/redux-thunk": "2.1.30",
29-
"autoprefixer": "6.4.0",
29+
"@types/webpack": "3.0.5",
30+
"@types/webpack-dev-server": "2.4.1",
31+
"autoprefixer": "7.1.2",
3032
"awesome-typescript-loader": "3.2.2",
3133
"classnames": "2.2.5",
32-
"css-loader": "0.24.0",
33-
"file-loader": "0.10.1",
34+
"css-loader": "0.28.4",
35+
"file-loader": "0.11.2",
3436
"husky": "0.14.3",
3537
"isomorphic-fetch": "2.2.1",
36-
"node-sass": "3.8.0",
37-
"postcss": "5.1.2",
38-
"postcss-loader": "0.11.0",
38+
"node-sass": "4.5.3",
39+
"postcss": "6.0.8",
40+
"postcss-loader": "2.0.6",
3941
"qrcode.react": "0.6.1",
4042
"raven-for-redux": "0.3.0",
4143
"raven-js": "3.12.1",
@@ -48,15 +50,16 @@
4850
"redux-logger": "2.6.1",
4951
"redux-thunk": "2.1.0",
5052
"reflexbox": "1.1.4",
51-
"sass-loader": "4.0.0",
52-
"style-loader": "0.13.1",
53+
"sass-loader": "6.0.6",
54+
"style-loader": "0.18.2",
55+
"ts-node": "^3.3.0",
5356
"tslib": "1.7.1",
5457
"tslint": "5.5.0",
5558
"typescript": "2.4.2",
5659
"typings-for-css-modules-loader": "1.5.0",
57-
"webpack": "1.13.1",
58-
"webpack-dev-middleware": "1.6.1",
59-
"webpack-dev-server": "1.14.1",
60-
"webpack-hot-middleware": "2.10.0"
60+
"webpack": "3.4.1",
61+
"webpack-dev-middleware": "1.12.0",
62+
"webpack-dev-server": "2.6.1",
63+
"webpack-hot-middleware": "2.18.2"
6164
}
6265
}

server.js

-35
This file was deleted.

src/styles/postcss.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
use: ["autoprefixer"]
3+
};

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"awesomeTypescriptLoaderOptions": {
2727
"useCache": true,
28-
"cacheDirectory": "./build/awCache"
28+
"cacheDirectory": "./.awCache"
2929
},
3030
"include": [
3131
"src",

0 commit comments

Comments
 (0)