-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(webpack): add webpack3 boilerplate with theming #2371
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
coverage/* | ||
dist/* | ||
docs/build/* | ||
examples/webpack3/scripts/* | ||
dll/* |
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 |
---|---|---|
|
@@ -75,11 +75,8 @@ These great products are built on Semantic UI React. Add yours [here][22]. | |
|
||
This is a listing of example projects and guides that will help you integrate Semantic UI React into your new or existing projects. | ||
|
||
### [webpack1][28] | ||
Our example project right [here][28] in this repo. | ||
|
||
### [webpack2][29] | ||
Our example project right [here][29] in this repo. | ||
### [webpack][28] | ||
Our example project right [here][28] in this repo. Includes theming examples. | ||
|
||
### [SUIcrux][102] | ||
Advanced universal starter with Semantic-UI-React. React/Redux/Lazy-loading/SSR/PWA. | ||
|
@@ -199,12 +196,11 @@ Big thanks to our [contributors][20], especially: | |
[21]: /~https://github.com/Semantic-Org/Semantic-UI-React/labels/good%20first%20issue | ||
[22]: /~https://github.com/Semantic-Org/Semantic-UI-React/edit/master/README.md | ||
[23]: https://react.semantic-ui.com/usage#css | ||
[24]: https://github.com/Semantic-Org/Semantic-UI-React/issues/802#issuecomment-258990274 | ||
[24]: https://medium.com/webmonkeys/webpack-2-semantic-ui-theming-a216ddf60daf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated link as information there has more value for our users. |
||
[25]: http://learnsemantic.com/themes/creating.html | ||
[26]: /~https://github.com/levithomason | ||
[27]: /~https://github.com/layershifter | ||
[28]: /~https://github.com/Semantic-Org/Semantic-UI-React/tree/master/examples/webpack1 | ||
[29]: /~https://github.com/Semantic-Org/Semantic-UI-React/tree/master/examples/webpack2 | ||
[28]: /~https://github.com/Semantic-Org/Semantic-UI-React/tree/master/examples/webpack3 | ||
[30]: /~https://github.com/Semantic-Org/Semantic-UI-Meteor | ||
|
||
<!-- Examples --> | ||
|
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react' | ||
import { Button, Container, Header, Segment } from 'semantic-ui-react' | ||
|
||
const LayoutsExample = () => ( | ||
<Container> | ||
<Segment basic padded> | ||
<Header | ||
as='h1' | ||
content='Theming' | ||
subheader='An introduction to theming' | ||
/> | ||
</Segment> | ||
|
||
<Segment basic padded> | ||
<Header as='h2' content='Preface' dividing /> | ||
<p> | ||
Semantic UI React does not have own styling system and fully relies on the theming of Semantic UI. It's really | ||
powerful, you don't need to know LESS or CSS you can simply update values of variables or use styles from | ||
predefined themes. | ||
</p> | ||
<p> | ||
In fact, all you know about theming and styling of Semantic UI is fully applicable to Semantic UI React. | ||
</p> | ||
<Button | ||
content='Learn more about theming' | ||
labelPosition='right' | ||
href='https://semantic-ui.com/usage/theming.html' | ||
icon='external link' | ||
target='_blank' | ||
/> | ||
<Button | ||
content='Creating themes' | ||
labelPosition='right' | ||
href='http://learnsemantic.com/themes/creating.html' | ||
icon='external link' | ||
target='_blank' | ||
/> | ||
|
||
<Header as='h2' content='Quick start' dividing /> | ||
<p> | ||
Semantic UI offers its own build system that uses Gulp and produces prepared CSS files. It makes sense to use it | ||
with Create React App as it does not support LESS loader. | ||
</p> | ||
<p> | ||
In all other cases we recommend to use the LESS package and tune it into your build system with Webpack. The | ||
LESS package also does not depend on Gulp and other cruft things. However, this package is not friendly for | ||
Webpack and requires additional configuration. | ||
</p> | ||
<Button | ||
content='Semantic UI LESS' | ||
labelPosition='right' | ||
href='/~https://github.com/Semantic-Org/Semantic-UI-LESS' | ||
icon='github' | ||
target='_blank' | ||
/> | ||
<Button | ||
content='Configuring Webpack' | ||
labelPosition='right' | ||
href='https://medium.com/webmonkeys/webpack-2-semantic-ui-theming-a216ddf60daf' | ||
icon='medium' | ||
target='_blank' | ||
/> | ||
|
||
<Header as='h2' content='Boilerplate' dividing /> | ||
<p> | ||
The boilerplate we prepared is powered by the latest Webpack and includes the all required things for quick | ||
start like preconfigured theming and hot module reload. | ||
</p> | ||
<p> | ||
The boilerplate is optimized for usage with Semantic UI React and Semantic UI LESS, it also contains examples | ||
of theming usage and custom components. | ||
</p> | ||
<Button | ||
content='Boilerplate' | ||
labelPosition='right' | ||
href='/~https://github.com/Semantic-Org/Semantic-UI-React/tree/master/examples/webpack3' | ||
icon='github' | ||
target='_blank' | ||
/> | ||
</Segment> | ||
</Container> | ||
) | ||
|
||
export default LayoutsExample |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Deprecated | ||
|
||
See [our boilerplate](../webpack3) for Webpack 3 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Deprecated | ||
|
||
See [our boilerplate](../webpack3) for Webpack 3 |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false, | ||
"targets": { | ||
"browsers": [ | ||
"last 2 versions", | ||
"ie >= 11", | ||
"safari >= 10" | ||
] | ||
} | ||
}], | ||
"@babel/react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-export-default-from", | ||
["direct-import", { "modules": [ | ||
"semantic-ui-react", { | ||
"name": "semantic-ui-react", | ||
"indexFile": "semantic-ui-react/dist/es/index.js" | ||
} | ||
]}], | ||
"lodash" | ||
], | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
"react-hot-loader/babel" | ||
] | ||
}, | ||
"production": { | ||
"plugins": [ | ||
"transform-react-remove-prop-types" | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const NODE_ENV = process.env.NODE_ENV | ||
|
||
if (!NODE_ENV) { | ||
throw new Error('The NODE_ENV environment variable is required but was not specified.') | ||
} | ||
|
||
// We support resolving modules according to `NODE_PATH`. | ||
// This lets you use absolute paths in imports inside large monorepos: | ||
// /~https://github.com/facebookincubator/create-react-app/issues/253. | ||
// It works similar to `NODE_PATH` in Node itself: | ||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders | ||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. | ||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. | ||
// /~https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 | ||
// We also resolve them to make sure all tools using them work consistently. | ||
const appDirectory = fs.realpathSync(process.cwd()) | ||
process.env.NODE_PATH = (process.env.NODE_PATH || '') | ||
.split(path.delimiter) | ||
.filter(folder => folder && !path.isAbsolute(folder)) | ||
.map(folder => path.resolve(appDirectory, folder)) | ||
.join(path.delimiter) | ||
|
||
function getClientEnvironment(publicUrl) { | ||
const raw = Object.keys(process.env) | ||
.reduce( | ||
(env, key) => { | ||
env[key] = process.env[key] // eslint-disable-line no-param-reassign | ||
return env | ||
}, | ||
{ | ||
// Useful for determining whether we’re running in production mode. | ||
// Most importantly, it switches React into the correct mode. | ||
NODE_ENV: process.env.NODE_ENV || 'development', | ||
// Useful for resolving the correct path to static assets in `public`. | ||
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />. | ||
// This should only be used as an escape hatch. Normally you would put | ||
// images into the `src` and `import` them in code to get their paths. | ||
PUBLIC_URL: publicUrl, | ||
} | ||
) | ||
// Stringify all values so we can feed into Webpack DefinePlugin | ||
const stringified = { | ||
'process.env': Object.keys(raw).reduce((env, key) => { | ||
env[key] = JSON.stringify(raw[key]) // eslint-disable-line no-param-reassign | ||
return env | ||
}, {}), | ||
} | ||
|
||
return { raw, stringified } | ||
} | ||
|
||
module.exports = getClientEnvironment |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const url = require('url') | ||
|
||
// Make sure any symlinks in the project folder are resolved: | ||
// /~https://github.com/facebookincubator/create-react-app/issues/637 | ||
const appDirectory = fs.realpathSync(process.cwd()) | ||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath) | ||
|
||
const envPublicUrl = process.env.PUBLIC_URL | ||
|
||
function ensureSlash(needlePath, needsSlash) { | ||
const hasSlash = needlePath.endsWith('/') | ||
if (hasSlash && !needsSlash) { | ||
return needlePath.substr(needlePath, needlePath.length - 1) | ||
} else if (!hasSlash && needsSlash) { | ||
return `${needlePath}/` | ||
} | ||
return needlePath | ||
} | ||
|
||
const getPublicUrl = appPackageJson => | ||
envPublicUrl || require(appPackageJson).homepage | ||
|
||
// We use `PUBLIC_URL` environment variable or "homepage" field to infer | ||
// "public path" at which the app is served. | ||
// Webpack needs to know it to put the right <script> hrefs into HTML even in | ||
// single-page apps that may serve index.html for nested URLs like /todos/42. | ||
// We can't use a relative path in HTML because we don't want to load something | ||
// like /todos/42/static/js/bundle.7289d.js. We have to know the root. | ||
function getServedPath(appPackageJson) { | ||
const publicUrl = getPublicUrl(appPackageJson) | ||
const servedUrl = | ||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/') | ||
return ensureSlash(servedUrl, true) | ||
} | ||
|
||
module.exports = { | ||
appBuild: resolveApp('build'), | ||
appNodeModules: resolveApp('node_modules'), | ||
appHtml: resolveApp('public/index.html'), | ||
appIndexJs: resolveApp('src/index.js'), | ||
appPackageJson: resolveApp('package.json'), | ||
appPublic: resolveApp('public'), | ||
appSrc: resolveApp('src'), | ||
publicUrl: getPublicUrl(resolveApp('package.json')), | ||
servedPath: getServedPath(resolveApp('package.json')), | ||
yarnLockFile: resolveApp('yarn.lock'), | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webpack 1&2 is outdated, we need only one boilerplate for latest version.