I'm having trouble using webpack instead of Codekit v1.9.3. I started working to move from CodeKit to Grunt and Gulp, and then learned about webpack
which sounds very cool. I just can't seem to get it working correctly.
"Like Codekit" means I can:
- Write
javascript
with thecoffeescript
syntax - Have all script source files and libraries minified / uglified and combined into one file
- Selectively include components of the
bootstrap-sass
(scss) framework as needed - Maintain a small file with bootstrap customizations via sass variables, like
$brand-primary
- Use
webpack --watch
to compile both scripts and styles automatically when they are changed - End up with one css file and one script file that can be included with a stylesheet and script tag.
Codekit Project Setup
Bower resources:
I'm currently storing these globally, outside of the project:
~/bower_components/twbs-bootstrap-sass/vendor/assets/stylesheets
Because CodeKit supports compass, I've got this in my config.rb
file:
add_import_path "~/bower_components/twbs-bootstrap-sass/vendor/assets/stylesheets"
Project Structure
js/fancybox.js
js/main.js <-- currently the compiled js 'output' file
js/main.coffee
css/styles.css <-- currently the compiled css 'output' file
scss/styles.scss
scss/modules/_bootstrap-customizations.scss
scss/modules/_typography.scss
scss/partials/_header.scss
scss/partials/_footer.scss
Contents of styles.scss
@import "modules/bootstrap-customizations"; # local customizations
@import "bootstrap/variables";
@import "bootstrap/mixins";
... # load bootstrap files as required
@import "bootstrap/wells";
System Setup:
- system: OS X 10.9
- node - v0.10.32
- npm - v2.1.7
- zsh - zsh 5.0.7 (x86_64-apple-darwin13.4.0)
node was installed with homebrew's brew install node
and seems to be working fine otherwise.
What I've Tried
I've read over these pages:
- http://webpack.github.io/docs/configuration.html
- https://github.com/petehunt/webpack-howto
- http://webpack.github.io/docs/tutorials/getting-started/
- https://www.npmjs.org/package/bootstrap-sass-webpack
I've attempted to create a webpack.config.js
file several times, my latest attempt was several versions of this:
module.exports = {
entry: [
"./node_modules/bootstrap-sass-webpack!./bootstrap-sass.config.js",
"./js/main.coffee"
],
output: {
path: __dirname,
filename: "main.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" }
]
}
};
Webpack Error
When I run webpack
I get this:
ERROR in ./~/bootstrap-sass-webpack/~/css-loader!/Users/cwd/~/sass-loader!./~/bootstrap-sass-webpack/bootstrap-sass-styles.loader.js!./bootstrap-sass.config.js
stdin:1: file to import not found or unreadable: "~bootstrap-sass/assets/stylesheets/bootstrap/variables
NPM Error
I get an error when attempting to npm install bootstrap-sass
, and not had any luck when searching for a solution. I'm not even sure I need this module.
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "bootstrap-sass"
npm ERR! node v0.10.32
npm ERR! npm v2.1.7
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package bootstrap-sass does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer bootstrap-sass-webpack@0.0.3 wants bootstrap-sass@~3.2.0
npm ERR! Please include the following file with any support request:
npm ERR! /Users/cwd/webpack-test/npm-debug.log
Sources of Confusion
The most confusing parts of webpack for me are:
- Where should things like
require("bootstrap-sass-webpack")
be added - is it in thewebpack.config.js
file, or in thejs/main.js
file? - Should modules like this available to webpack as soon as they are installed with
npm install
? - I thought that I should do
npm install webpack -g
so that webpack was installed globally, and usenpm install
without the-g
for the other modules. However, I don't see anynode_modules
folder being created in my project. Shouldn't there be one? - How are the search paths determined / specified for things like
require("bootstrap-sass-webpack")
?
What node modules should I install to be able to do this? And what should my webpack.config.js
look like?