Skip to content

Commit 8b8d67b

Browse files
Updates
1 parent 5e91a32 commit 8b8d67b

File tree

71 files changed

+988
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+988
-361
lines changed

.babelrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
dist/
21
node_modules/
3-
4-
/*/
5-
!/src
6-
7-
/index.js
2+
/dist

.npmignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
# Topcoder Navigation React
22

3-
## Demo
43

54
### Build the components
65

76
Enter `navigation-component` and run:
87

98
- `npm install`
10-
- `npm run build:lib`
9+
- `npm run build`
1110

12-
### Run the demo
11+
Due to this repo is not npm package, so keep `dist` folder for other project use it
1312

14-
Run the following in the `navigation-component-demo` folder:
1513

16-
- `yarn`
17-
- `yarn start`
14+
## Getting Started
15+
16+
### Install
1817

19-
### Troubleshooting
18+
```
19+
npm install [email protected]:username/navigation-component.git#develop --save
20+
```
2021

21-
If you encounter invalid hook call error while running the demo, then:
22+
### Usage
23+
- Example
24+
```
25+
import { TopNav } from 'navigation-component'
26+
```
2227

23-
- delete navigation-component-demo/node_modules/navigation-component/node_modules/react
24-
- delete navigation-component-demo/node_modules/navigation-component/node_modules/react-dom
28+
### Development
2529

26-
and try again.
30+
```shell
31+
Install dependencies
32+
$ npm install
2733

28-
## Getting Started
34+
# Run build
35+
$ npm run build
2936

30-
### Install
37+
#Go to other project which depends on the navigation-component, config its package.json so that the 'navigation-component' points to the local folder path of navigation-component:
3138

32-
```
33-
npm i -D navigation-component
34-
```
39+
# "dependencies": {
40+
# "navigation-component": "<local-path-to-navigation-component>",
41+
# ......
42+
# }
3543

36-
### Assets
44+
# If you faced React Hook errors. Please remove 'node_modules', 'src' folder when you try it
3745

38-
Copy `dist/font` and `dist/img` to web server root folder. You can put them nested in sub folder, but be sure to update `$font-path` and `$img-path` SASS variables in the `src/assets/sass/_global/_variables.scss`.
46+
```

build.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

config/webpack/development.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const configFactory = require('./lib-development')
2+
const path = require('path')
3+
4+
const standardConfig = configFactory({
5+
context: path.resolve(__dirname, '../..'),
6+
entry: './src',
7+
library: 'navigation-component'
8+
})
9+
10+
module.exports = standardConfig

config/webpack/lib-base.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/**
2+
* Base Webpack configuration for ReactJS libraries. It is further extended for
3+
* development and production use in the "lib-development" and "lib-production"
4+
* configs.
5+
*/
6+
7+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
8+
const path = require('path')
9+
const webpack = require('webpack')
10+
11+
/**
12+
* Creates a new Webpack config object.
13+
*
14+
* @param {Object} ops Configuration params. This allows to conveniently set
15+
* the options that should be customized for specific libraries.
16+
*
17+
* @param {String} ops.babelEnv BABEL_ENV to be used by Babel during the build.
18+
*
19+
* @param {String} ops.context Base URL for resolution of relative config paths.
20+
*
21+
* @param {String} ops.cssLocalIdent Template for CSS classname
22+
* generation by css-loader (it will be passed into the "localIdentName" param
23+
* of the loader). It should match the corresponding setting in the Babel
24+
* config.
25+
*
26+
* @param {String} ops.entry Entry point of the library.
27+
*
28+
* @param {String} ops.library Name of the library.
29+
*
30+
* @param {String} ops.outputPath Output path.
31+
*
32+
* @return {Object} Webpack config.
33+
*/
34+
module.exports = function configFactory (ops) {
35+
return {
36+
context: ops.context,
37+
entry: ops.entry,
38+
externals: [
39+
/@babel\/runtime/,
40+
'lodash',
41+
'moment',
42+
'prop-types',
43+
'react',
44+
'react-css-super-themr',
45+
/react-dom/,
46+
'react-helmet',
47+
/react-hot-loader/,
48+
'react-redux',
49+
'react-router-dom',
50+
'redux',
51+
'redux-actions',
52+
'redux-devtools',
53+
'redux-devtools-dock-monitor',
54+
'redux-devtools-log-monitor',
55+
'redux-promise',
56+
'shortid',
57+
'topcoder-react-utils',
58+
'url-parse'
59+
],
60+
mode: ops.mode,
61+
output: {
62+
filename: 'index.js',
63+
64+
// Workaround to fix umd build, restore webpack v3 behaviour
65+
// https://github.com/webpack/webpack/issues/6677
66+
// https://github.com/webpack/webpack/issues/6642
67+
globalObject: "typeof self !== 'undefined' ? self : this",
68+
69+
library: ops.library,
70+
path: ops.outputPath,
71+
libraryTarget: 'umd'
72+
},
73+
plugins: [
74+
new webpack.DefinePlugin({
75+
'process.env': {
76+
BABEL_ENV: JSON.stringify(ops.babelEnv),
77+
NODE_ENV: JSON.stringify(ops.babelEnv)
78+
}
79+
}),
80+
new MiniCssExtractPlugin({
81+
filename: 'style.css'
82+
})
83+
],
84+
module: {
85+
rules: [{
86+
/* Handles fonts imports in url(..) instructions in CSS. Effectively,
87+
* with such configuration it just rewrites those URLs to point to
88+
* the original location of the fonts assets in
89+
* the library being build. */
90+
test: /\.(ttf|eot|svg)$/,
91+
include: [
92+
/src[/\\]assets[/\\]fonts/
93+
],
94+
loader: 'file-loader',
95+
options: {
96+
name: './[name].[ext]',
97+
outputPath: 'fonts/'
98+
}
99+
},
100+
{
101+
test: /\.(svg)$/,
102+
include: [
103+
/src[/\\]assets[/\\]images/
104+
],
105+
loader: 'file-loader',
106+
options: {
107+
name: './[name].[ext]',
108+
outputPath: 'images/'
109+
}
110+
},
111+
{
112+
// Match woff2 in addition to patterns like .woff?v=1.1.1.
113+
test: /\.(woff|woff2)$/,
114+
use: {
115+
loader: 'url-loader',
116+
options: {
117+
// Limit at 20k. Above that it emits separate files
118+
limit: 20000,
119+
120+
// url-loader sets mimetype if it's passed.
121+
// Without this it derives it from the file extension
122+
mimetype: 'application/font-woff',
123+
124+
// Output below fonts directory
125+
name: 'fonts/[name].[ext]'
126+
}
127+
}
128+
},
129+
{
130+
/* Loads JS and JSX moudles, and inlines SVG assets. */
131+
test: /\.(jsx?)$/,
132+
exclude: [
133+
/node_modules/,
134+
/src[/\\]assets[/\\]fonts/
135+
],
136+
loader: 'babel-loader',
137+
options: {
138+
babelrc: false,
139+
envName: ops.babelEnv,
140+
presets: ['topcoder-react-utils/config/babel/webpack']
141+
}
142+
},
143+
{
144+
test: /\.svg$/,
145+
include: [
146+
/src[/\\]assets[/\\]images/
147+
],
148+
use: {
149+
loader: 'url-loader',
150+
options: {
151+
// Limit at 20k. Above that it emits separate files
152+
limit: 20000,
153+
mimetype: 'image/svg',
154+
name: 'images/[name].[ext]'
155+
}
156+
}
157+
},
158+
{
159+
oneOf: [
160+
{
161+
test: /\.module\.(css|sass|scss)$/,
162+
use: [
163+
'style-loader',
164+
{
165+
loader: 'css-loader',
166+
options: {
167+
modules: true
168+
}
169+
},
170+
'sass-loader'
171+
]
172+
},
173+
{
174+
test: /\.(css|sass|scss)$/,
175+
use: ['style-loader', 'css-loader', 'sass-loader']
176+
}
177+
]
178+
}
179+
]
180+
},
181+
resolve: {
182+
alias: {
183+
/* Aliases to JS an JSX files are handled by Babel. */
184+
assets: path.resolve(ops.context, 'src/assets'),
185+
components: path.resolve(ops.context, 'src/components'),
186+
fonts: path.resolve(ops.context, 'src/assets/fonts'),
187+
styles: path.resolve(ops.context, 'src/assets/sass')
188+
},
189+
extensions: ['.js', '.scss'],
190+
symlinks: false
191+
}
192+
}
193+
}

config/webpack/lib-development.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Development Webpack configuration for ReactJS libraries.
3+
*/
4+
5+
const path = require('path')
6+
const baseFactory = require('./lib-base')
7+
8+
/**
9+
* Creates a new Webpack config.
10+
*
11+
* @param {Object} ops Configuration params. This helps to conveniently set
12+
* the most useful options. You still can modify other config parameters with
13+
* help of "webpack-merge", or by a direct mutation of the created config
14+
* object.
15+
*
16+
* @param {String} ops.context Base URL for resolution of relative config
17+
* paths.
18+
*
19+
* @param {String} ops.entry Entry point of the library.
20+
*
21+
* @return {Object} Webpack configuration.
22+
*/
23+
module.exports = function configFactory (ops) {
24+
return baseFactory({
25+
...ops,
26+
babelEnv: 'development',
27+
cssLocalIdent: '[path][name]___[local]___[hash:base64:6]',
28+
mode: 'development',
29+
outputPath: path.resolve(__dirname, ops.context, 'dist/dev')
30+
})
31+
}

0 commit comments

Comments
 (0)