-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Damien Golding
committed
Apr 26, 2020
0 parents
commit bb38c41
Showing
4 changed files
with
184 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
# This project | ||
dist | ||
vendor | ||
build | ||
tmp |
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 @@ | ||
# Description | ||
|
||
Collection of Webpack helper functions. |
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,101 @@ | ||
const webpack = require('webpack') | ||
|
||
const WebpackHelpers = { | ||
mode: () => { | ||
// https://webpack.js.org/configuration/mode/ | ||
function setEnvironmentVariable(currentValue, defaultValue) { | ||
const aliases = { | ||
dev: 'development', | ||
prod: 'production' | ||
} | ||
if (aliases[currentValue]) { | ||
currentValue = aliases[currentValue] | ||
} | ||
if (!currentValue) { | ||
currentValue = defaultValue | ||
} | ||
return currentValue | ||
} | ||
|
||
console.log('Current process.env.NODE_ENV:', process.env.NODE_ENV) // TODO: Logs not going through. Is this NODE_ENV even going through consider NODE_ENV might just be local to that terminal. | ||
const mode = setEnvironmentVariable(process.env.NODE_ENV, 'production') // TODO: Use constants. | ||
console.log('Set mode:', mode) | ||
return mode | ||
}, | ||
Rules: { | ||
json: () => { | ||
const { | ||
delimitedArrayToReadableStringMap | ||
} = (require('js-functions')).BaseUtility | ||
|
||
return { | ||
test: /messages\.json$/, | ||
loaders: [{ | ||
loader: 'content-loader', | ||
options: { | ||
/** | ||
* @param {string} data | ||
*/ | ||
function: (data) => { // TODO: Name this as automatic way of setting keys. | ||
/** | ||
* @type {Object} | ||
*/ | ||
const object = JSON.parse(data) | ||
const keys = Object.keys(object) | ||
const map = delimitedArrayToReadableStringMap(keys, '-') | ||
return JSON.stringify(map) | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
htmlString: () => { | ||
return { | ||
test: /\.html$/, | ||
loaders: [ | ||
'raw-loader' | ||
] | ||
} | ||
}, | ||
cssString: () => { | ||
return { | ||
test: /\.css$/, | ||
loaders: [ | ||
'to-string-loader', | ||
'css-loader' | ||
] | ||
} | ||
}, | ||
image: () => { | ||
return { | ||
test: /\.(jpe?g|png|gif|svg)$/i, | ||
loader: 'file-loader', | ||
options: { | ||
name: '[name].[ext]', | ||
outputPath: 'components/assets/images/' | ||
// the images will be emited to dist/.../components/assets/images/ folder | ||
} | ||
} | ||
} | ||
}, | ||
Plugins: { | ||
jquery: () => { | ||
// Use the ProvidePlugin constructor to inject jquery implicit globals | ||
return new webpack.ProvidePlugin({ | ||
$: 'jquery', | ||
jQuery: 'jquery', | ||
'window.jQuery': "jquery'", | ||
'window.$': 'jquery' | ||
}) | ||
}, | ||
bundleAnalyzer: () => { | ||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') | ||
// https://github.com/webpack-contrib/webpack-bundle-analyzer | ||
return new BundleAnalyzerPlugin({ | ||
analyzerMode: 'static' | ||
}) | ||
} | ||
} | ||
} | ||
|
||
module.exports = WebpackHelpers |
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,15 @@ | ||
{ | ||
"name": "webpack-helpers", | ||
"version": "1.0.0", | ||
"description": "Collection of webpack helpers for easily generating config.", | ||
"main": "index.js", | ||
"scripts": { | ||
|
||
}, | ||
"keywords": [], | ||
"author": "Damien Golding", | ||
"license": "MIT", | ||
"dependencies": { | ||
"js-functions": "git+https://github.com/goldingdamien/js-functions.git" | ||
} | ||
} |