After spending a few days on this issue, I decided to create a boilerplate so other developers don't run into the same issues I did when trying to add Semantic UI to a project of my own.
-
Clone the repo
-
Install dependencies via
npm- Note:
yarnusers will encounter issues installingsemantic-uisource, if this occurs kill the process and run:
npm i semantic-ui
- Note:
-
Run the font path fix.
-
Run
node font-fix.jsfrom the command line -
There is an incorrect transformation that occurs with the relative paths when using webpack, we need to run this any time we update/install semantic-ui If you don't care about semantic-ui bundled fonts, then do not run this font fix command; amend your webpack config as follows:
{ test: /\.less$/, // import css from 'foo.less'; use: [ 'style-loader', { loader: 'css-loader', options: { url: false } }, 'less-loader' ] }
-
-
Start the webpack dev server
git clone https://github.com/atomicpages/semantic-ui-webpack2-boilerplate.git
npm i
node font-fix.js
npm startCurrently, the best way to do this is to develop your theme inside of the semantic folder (or wherever your assets are insatlled) and then make a copy in the root. Due to the ridged nature of Semanitc UI, it might not be possible to do this otherwise. Other options:
-
Scrap
lessimports and amendwebpack.config.jsas follows:{ test: /\.css$/, // changed from \.less$ use: [ 'style-loader', 'css-loader' ] }
If you ran
font-fix.jswe need to undo what we did. To do this delete thesemanticfolder and reinstall usingnpmOnce this is complete we can now buildsemantic-uiindependently of Webpack:cd semantic gulp build gulp watchinside of
app/index.jsmake the following change:import css from '../semantic/dist/semantic.css';
Note: if you've set aliases ensure those are updated for the proper path.
Due to the rigid nature of Webpack and Semantic UI, they don't mingle very well. To by pass this, we can develop our theme inside of the semantic source folder directly and use gulp tasks to copy it to our project root.
gulp copy-to # copies to semantic folder
gulp copy-from # copies from the semantic folder
gulp copy-theme-config # copies theme.config to project root; run with copy-from by defaultIn order to get webpack to deploy the new changes, all modifications to theme files must be done inside the semantic-ui folder.
Just run npm run build
-
URL issues with some assets not able to be found
Based on experience, this is usually an issue with the way paths are resolved in webpack. There are two solutions:
- Fix the path to be correct (like
font-fix.js) - Tell
css-loaderto ignore urls
- Fix the path to be correct (like
- Node 10.x+