-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade & simplify webpack example (#343)
* (webpack) - upgrade webpack example packages * (webpack) - simplify webpack example config * (webpack) - simplify webpack example counter
- Loading branch information
Showing
6 changed files
with
1,355 additions
and
1,646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { useState } from 'preact/hooks'; | ||
|
||
export const useCounter = initialValue => { | ||
export const useCounter = () => { | ||
const [state, setState] = useState(0); | ||
return [state, () => setState(state + 2)]; | ||
return [state, () => setState(state + 1)]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,33 @@ | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const PreactRefreshPlugin = require('@prefresh/webpack'); | ||
|
||
const makeConfig = () => { | ||
const { NODE_ENV } = process.env; | ||
module.exports = (env) => { | ||
const { NODE_ENV = 'development' } = env; | ||
const isProduction = NODE_ENV === 'production'; | ||
|
||
// Build plugins | ||
const plugins = [ | ||
new HtmlWebpackPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify(NODE_ENV), | ||
}), | ||
]; | ||
|
||
if (!isProduction) { | ||
plugins.push(new PreactRefreshPlugin()); | ||
plugins.push(new webpack.HotModuleReplacementPlugin()); | ||
plugins.push(new PreactRefreshPlugin()); | ||
} | ||
|
||
// Return configuration | ||
return { | ||
mode: isProduction ? 'production' : 'development', | ||
entry: './src/index.js', | ||
stats: 'normal', | ||
devServer: { | ||
contentBase: path.join(__dirname, 'dist'), | ||
host: 'localhost', | ||
port: 3000, | ||
historyApiFallback: true, | ||
hot: true, | ||
inline: true, | ||
publicPath: '/', | ||
clientLogLevel: 'none', | ||
open: true, | ||
overlay: true, | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
publicPath: '/', | ||
}, | ||
resolve: { | ||
alias: { | ||
preact: path.resolve(__dirname, 'node_modules', 'preact'), | ||
}, | ||
}, | ||
plugins, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$|\.jsx$/, | ||
include: [path.resolve(__dirname, 'src')], | ||
test: /\.jsx?$/, | ||
loader: 'babel-loader', | ||
}, | ||
], | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = makeConfig(); |
Oops, something went wrong.