Skip to content

Commit

Permalink
docs(bundlers): add webpack 2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and Alexander Fedyashov committed Mar 23, 2017
1 parent 3fd65da commit 199877e
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/app/Views/Usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ const Usage = () => (
icon='github'
labelPosition='left'
/>

<Header as='h3'>Webpack 2</Header>
<p>
Webpack 2 fully supports Semantic UI React, it also supports tree shaking. Please ensure that you build your app
in production mode before release, it will strip <code>propTypes</code> from your build.
</p>

<Button
content='Example configuration'
href='https://github.com/Semantic-Org/Semantic-UI-React/tree/master/examples/webpack2'
icon='github'
labelPosition='left'
/>
</Segment>
</Container>
)
Expand Down
2 changes: 1 addition & 1 deletion examples/webpack1/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="root" style="height: 100%"></div>
<script src="./dist/bundle.js"></script>
<script src="./dist/app.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/webpack1/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const App = () => (
</Container>
)

render(App, MOUNT_NODE)
render(<App />, MOUNT_NODE)
10 changes: 10 additions & 0 deletions examples/webpack2/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
["es2015", {"modules": false}],
"react",
"stage-1"
],
"plugins": [
"lodash"
]
}
1 change: 1 addition & 0 deletions examples/webpack2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
27 changes: 27 additions & 0 deletions examples/webpack2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "semantic-ui-react-example-webpack2",
"version": "1.0.0",
"description": "Get started with Semantic UI React and Webpack 2",
"main": "index.js",
"scripts": {
"build": "webpack",
"build:production": "cross-env NODE_ENV=production npm run build"
},
"author": "Alexander Fedyashov <a@fedyashov.com>",
"license": "MIT",
"dependencies": {
"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-1": "^6.22.0",
"cross-env": "^3.2.3",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"semantic-ui-react": "^0.67.0",
"webpack": "^2.3.0"
},
"devDependencies": {
"webpack-bundle-analyzer": "^2.3.1"
}
}
13 changes: 13 additions & 0 deletions examples/webpack2/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<title>Semantic UI React Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.9/semantic.min.css">
</head>
<body>
<div id="root" style="height: 100%"></div>
<script src="./dist/app.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/webpack2/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { render } from 'react-dom'
import { Button, Container, Header } from 'semantic-ui-react'

const MOUNT_NODE = document.getElementById('root')

const App = () => (
<Container>
<Header as='h1'>Hello world!</Header>

<Button
content='Discover docs'
href='http://react.semantic-ui.com'
icon='github'
labelPosition='left'
/>
</Container>
)

render(<App />, MOUNT_NODE)
63 changes: 63 additions & 0 deletions examples/webpack2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const path = require('path')
const webpack = require('webpack')

const env = process.env.NODE_ENV || 'development'

const webpackConfig = {
name: 'client',
target: 'web',

entry: {
app: path.resolve('src/main.js'),
},

module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
}],
},

plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
new BundleAnalyzerPlugin(),
],

output: {
filename: '[name].js',
path: path.resolve('public/dist'),
publicPath: '/',
},

resolve: {
modules: [
path.resolve('src'),
'node_modules',
],
extensions: ['.js', '.jsx'],
},
}

if (env === 'production') {
webpackConfig.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
},
})
)
}

module.exports = webpackConfig

0 comments on commit 199877e

Please sign in to comment.