Skip to content

Commit 8c863e2

Browse files
committed
separate file for webpack.dev and webpack.prod
1 parent 2f45955 commit 8c863e2

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dev-dist
12
dist
23
node_modules
34
.DS_Store

Diff for: .npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ src
44
build
55
!.eslintrc
66
yarn-error.log
7+
dev-dist
78

89
*.js
910
!dist/index.js

Diff for: index.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</title>
77
</head>
88
<body>
9+
<h1>test</h1>
910
<div id="app">
1011

1112
</div>

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "React timer hook is a custom react hook built to handle timers, stopwatch and timer logic and state in your react component.",
55
"main": "dist/index.js",
66
"scripts": {
7-
"build:dev": "webpack && webpack-dev-server",
8-
"build:prod": "rm -rf ./dist && webpack"
7+
"build:dev": "webpack --config webpack.dev.js && webpack-dev-server --open --config webpack.dev.js",
8+
"build:prod": "rm -rf ./dist && webpack --config webpack.prod.js"
99
},
1010
"repository": {
1111
"type": "git",

Diff for: webpack.config.js renamed to webpack.dev.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module.exports = {
77
performance: {
88
hints: false
99
},
10-
mode: "production",
10+
mode: "development",
1111
entry: './src/index.js',
1212
output: {
1313
filename: 'js/scripts.js',
1414
chunkFilename: '[name].[chunkhash].js',
15-
path: path.resolve(__dirname, 'dist'),
15+
path: path.resolve(__dirname, 'dev-dist'),
1616
},
1717
module: {
1818
rules: [{
@@ -27,12 +27,11 @@ module.exports = {
2727
plugins: [
2828
new CopyWebpackPlugin([
2929
{ from: './index.html', to: './' },
30-
{ from: './src/useTimer.js', to: './index.js' }
3130
]),
3231
],
3332
devServer: {
34-
contentBase: path.join(__dirname, 'dist'),
33+
contentBase: path.join(__dirname, 'dev-dist'),
3534
compress: true,
3635
port: 9000
3736
}
38-
}
37+
}

Diff for: webpack.prod.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path')
2+
3+
4+
module.exports = {
5+
performance: {
6+
hints: false
7+
},
8+
mode: "production",
9+
entry: './src/useTimer.js',
10+
output: {
11+
filename: './index.js',
12+
// chunkFilename: '[name].[chunkhash].js',
13+
// path: path.resolve(__dirname, 'dist'),
14+
library: 'react-timer-hook',
15+
libraryTarget: "umd"
16+
},
17+
module: {
18+
rules: [{
19+
test: /\.js$/,
20+
// exclude: /node_modules/,
21+
loader: 'babel-loader',
22+
options: {
23+
presets: ['env', 'es2015', 'react', 'stage-1'],
24+
}
25+
}]
26+
},
27+
externals: [
28+
'react',
29+
// Everything that starts with "library/"
30+
/^react\/.+$/,
31+
],
32+
}

0 commit comments

Comments
 (0)