Skip to content

Commit 9752a06

Browse files
committed
Re-organize webpack config into common, dev and prod configs
1 parent 37dc713 commit 9752a06

8 files changed

+91
-77
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ script:
1515
- yarn run lint
1616

1717
before_deploy:
18-
- yarn run webpack --mode production
18+
- yarn run build
1919

2020
deploy:
2121
provider: pages

dist/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<div id="game"></div>
1414
<p id="version"></p>
1515
<p id="about">Made by <a href="https://github.com/cmfcmf">Christian Flach</a>.</p>
16-
<script src="main.js"></script>
16+
<script src="app.bundle.js"></script>
1717
</body>
1818
</html>

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747
"uglifyjs-webpack-plugin": "^1.2.6",
4848
"webpack": "^4.12.0",
4949
"webpack-cli": "^3.0.3",
50-
"webpack-dev-server": "^3.1.4"
50+
"webpack-dev-server": "^3.1.4",
51+
"webpack-merge": "^4.1.3"
5152
},
5253
"scripts": {
53-
"start": "webpack-dev-server --host 0.0.0.0",
54-
"build": "webpack",
54+
"start": "webpack-dev-server --host 0.0.0.0 --config webpack.dev.js",
55+
"build": "webpack --config webpack.prod.js",
5556
"lint": "tslint --project .",
5657
"test": "jest",
5758
"test-watch": "jest --notify --watchAll",

webpack.common.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const path = require("path");
2+
const webpack = require("webpack");
3+
const GitRevisionPlugin = require("git-revision-webpack-plugin");
4+
const gitRevisionPlugin = new GitRevisionPlugin({
5+
// branch: true,
6+
});
7+
const CopyWebpackPlugin = require("copy-webpack-plugin");
8+
9+
/* tslint:disable */
10+
module.exports = {
11+
entry: {
12+
app: [
13+
"idb.filesystem.js",
14+
"@babel/polyfill",
15+
"./src/index.ts",
16+
],
17+
},
18+
plugins: [
19+
gitRevisionPlugin,
20+
new webpack.DefinePlugin({
21+
'__VERSION__': JSON.stringify(gitRevisionPlugin.version()),
22+
// '__COMMITHASH__': JSON.stringify(gitRevisionPlugin.commithash()),
23+
// '__BRANCH__': JSON.stringify(gitRevisionPlugin.branch()),
24+
}),
25+
new CopyWebpackPlugin([
26+
{from: "./node_modules/smk2mp4/demo/ffmpeg.js", to: 'ffmpeg.js'},
27+
{from: "./node_modules/smk2mp4/demo/ffmpeg.js.mem", to: 'ffmpeg.js.mem'},
28+
]),
29+
],
30+
module: {
31+
rules: [
32+
{
33+
test: /\.tsx?$/,
34+
use: [
35+
{
36+
loader: "babel-loader",
37+
options: {
38+
presets: ['@babel/preset-env']
39+
},
40+
},
41+
{
42+
loader: "ts-loader",
43+
},
44+
],
45+
exclude: /node_modules/,
46+
},
47+
],
48+
},
49+
resolve: {
50+
extensions: [".tsx", ".ts", ".js"],
51+
},
52+
output: {
53+
filename: "[name].bundle.js",
54+
path: path.resolve(__dirname, "dist"),
55+
},
56+
};

webpack.config.js

-72
This file was deleted.

webpack.dev.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const merge = require('webpack-merge');
2+
const common = require('./webpack.common.js');
3+
4+
const webpack = require("webpack");
5+
6+
module.exports = merge(common, {
7+
mode: "development",
8+
devtool: "inline-source-map",
9+
devServer: {
10+
contentBase: "./dist",
11+
hot: true,
12+
},
13+
plugins: [
14+
new webpack.HotModuleReplacementPlugin(),
15+
]
16+
});

webpack.prod.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const merge = require('webpack-merge');
2+
const common = require('./webpack.common.js');
3+
4+
module.exports = merge(common, {
5+
mode: "production",
6+
devtool: "source-map",
7+
});

yarn.lock

+6
Original file line numberDiff line numberDiff line change
@@ -6523,6 +6523,12 @@ webpack-log@^1.0.1, webpack-log@^1.1.2:
65236523
loglevelnext "^1.0.1"
65246524
uuid "^3.1.0"
65256525

6526+
webpack-merge@^4.1.3:
6527+
version "4.1.3"
6528+
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.3.tgz#8aaff2108a19c29849bc9ad2a7fd7fce68e87c4a"
6529+
dependencies:
6530+
lodash "^4.17.5"
6531+
65266532
webpack-sources@^1.0.1, webpack-sources@^1.1.0:
65276533
version "1.1.0"
65286534
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54"

0 commit comments

Comments
 (0)