Awesome
foundation-sites-loader
Foundation configuration and loading package for webpack, using the npm packages foundation-sites
and sass-loader
.
Install from foundation-sites-loader on npm.
In a nutshell:
- You've got the sass-loader to process Sass files to CSS.
- The npm foundation-sites package places the foundation files in
/node_modules/foundation-sites
. - You could simply create your own sass file to pick up foundation from this location, and you could require the js files here for the Foundation JavaScript code. See the sass-loader for instructions on configuring the directories.
- Or you could use this loader and load a js file that configures Foundation.
Note, foundation-sites
must be installed locally inside of ../node_modules
or a parent directories node_modules
directory relative to the loaded config file.
Foundation Version
The version of foundation-sites used is listed in peerDependencies, so you should be able to use whichever version you like.
Simply specify that version of foundation-sites
in your package.json
, like this:
"foundation-sites": "~6.1.2"
Usage
1.a Complete Foundation
To use the complete foundation package including styles and scripts with the default settings:
require("foundation-sites-loader");
The disadvantage to using this setup is that you can't:
- Customize the foundation variables: Foundation Customization
- You can't use the foundation variables for your own sass stylesheets.
1.b Customized Foundation
- Copy the file
foundation-sites.config.js
to your project. You will specify the file path in therequire
statement. - Open that file to customize the location of a file for any Foundation variable overrides (
preFoundationCustomizations
andfoundationCustomizations
, and your main Sass file that can depend on Foundation variables, plus your customizations. Any of these 3 files are optional. You may also remove any Sass or Js modules that you don't need.
Next, you should specify this as an entry point:
module.exports = {
entry: [
"foundation-sites!./path/to/foundation-sites.config.js"
]
Or a dependency within a file, like you'd specify other webpack dependencies:
require("foundation-sites!./path/to/foundation-sites.config.js");
foundation-sites.config.js
Here's a sample configuration file. The file included in the foundation-sites-loader git repo
has many more options. The two customization files, foundationCustomizations
and mainSass
are optional.
module.exports = {
foundationCustomizations: "./foundation-customizations.scss",
mainSass: "./main.scss", // path to your main SASS file (optional)
verbose: true, // print out your custom files used
debug: false, // print out the full generated scss file
styleLoader: "style-loader!css-loader!sass-loader", // see example for the ExtractTextPlugin
scripts: {
// add every foundation script you need
'foundation.core': true,
'foundation.accordion': true
},
styles: {
// add every foundation style you need
'mixins': true,
'normalize': true,
'print': true,
'glyphicons': true
}
};
Example Loaders Configuration:
module.exports = {
module: {
loaders: [
// **IMPORTANT** This is needed so that each foundation js file required by
// foundation-webpack has access to the jQuery object
{ test: /foundation\/js\//, loader: 'imports?jQuery=jquery' }
]
}
};
extract-text-plugin Notes
- If you don't run webpack like this, you might get a very obscure error:
PATH=$(npm bin):$PATH webpack --config webpack.rails.config.js
Alternate, you can put $(npm bin) in your path. Basically if you run type webpack
and the path is your global one, then
you may have issues.
- You can configure the output file of the created CSS file by using a relative path to the output directory. For example:
plugins: [
new ExtractTextPlugin("../stylesheets/foundation-and-customizations.css")
]
Based on:
Known Issues
- Automatic Dependency loading is currently problematic. If you "touch" either of the customization files listed in your config file (foundationCustomizations, mainSass), then that will trigger a rebuild of the Sass files. This is a known issue with the sass-loader. I work around this issue by "touching" one of the 3 sass config files.
Testing Changes in the Foundation Sites Loader
- See this article Debugging NodeJs and Webpack Loaders
- Use the npm link command per step #1 (see article)
- Be sure to run
npm i foundation-sites
in the directory where you have thefoundation-sites-loader
. This is because the location of foundation-sites is found relative to thefoundation-sites-loader
and if you linked it and it's not not there, then you'll bet this error: "Error: Could not find path to foundation-sites. Check to see that it's in a parent directory of config file containing node_modules/foundation-sites".
Pull requests are welcome!
Code Inspection and ESLint
- If using Webstorm import the inspection file in /jetbrains-inspection and inspect all files
- Command line:
eslint .
Publishing to NPM
- Install the release-it npm program
- Merge fixes to master
- Run command
release-it
- Take defaults, except for last one to publish changes (answer Y)