Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

feat(webpack): enable user to provide aliases though new config key #379

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ file at the root of your project.
- [serviceWorker](#serviceWorker)
- [targetBrowsers](#targetBrowsers)
- [extends](#extends)
- [webpack](#webpack)
- [alias](#alias)
- [rootElementId](#rootElementId)

## <a id='routes'></a>[`routes`](#routes)
Expand Down Expand Up @@ -212,6 +214,13 @@ If you want to run your application without headers, you can define here the ele

Make your .vitaminrc extends another vitamin config. It is useful in case you want to have a base configuration for multiple environments.

## <a id='webpack'></a>[`webpack`](#webpack)
Endpoint to customize some specific webpack config.
### <a id='alias'></a>[`alias`](#alias)
**`Object`**
Add your own aliases for custome resolution.


# Globals
## <a id='isclient-isserver'></a>[`IS_CLIENT` / `IS_SERVER`](#isclient-isserver)
Two globals are available everywhere in your application : `IS_SERVER` and `IS_CLIENT`. When bundling your application `vitaminjs` will replace them with `true`/`false` depending on the environment.
5 changes: 4 additions & 1 deletion config/build/webpack.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export function config(options) {
},
cache: options.hot,
resolve: {
alias: options.moduleMap,
alias: {
...options.webpack.alias,
...options.moduleMap,
},
modules: MODULES_DIRECTORIES,
extensions: ['.js', '.jsx', '.json', '.css'],
mainFields: ['browser', 'module', 'main', 'style'],
Expand Down
3 changes: 3 additions & 0 deletions config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default {
'not ie < 9', // react doesn't support ie < 9
],
},
webpack: {
alias: {},
},
filesPath: 'files',
rootElementId: 'vitamin-app',
};
7 changes: 7 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ export default () => {
updatePath(path, appResolve, config),
);

// Resolve user webpack alias to absolute paths
Object.keys(config.webpack.alias)
.map(aliasKey => ['webpack', 'alias', aliasKey])
.forEach(path =>
updatePath(path, appResolve, config),
);

// Prepend / to publicPath and basePath if necessary
const prependSlash = path => (
((path.startsWith('/') || path.match(/^(http|\/|$)/)) ? '' : '/') + path
Expand Down