【发布时间】:2015-01-07 04:32:00
【问题描述】:
我在使用 webpack 而不是 Codekit v1.9.3 时遇到问题。我开始从 CodeKit 迁移到 Grunt 和 Gulp,然后了解了 webpack,这听起来很酷。我似乎无法让它正常工作。
“喜欢 Codekit”意味着我可以:
- 使用
coffeescript语法编写javascript - 将所有脚本源文件和库压缩/丑化并合并到一个文件中
- 根据需要选择性地包含
bootstrap-sass(scss) 框架的组件 - 通过 sass 变量维护一个带有引导自定义的小文件,例如
$brand-primary - 使用
webpack --watch在脚本和样式发生更改时自动编译它们 - 最终得到一个 css 文件和一个脚本文件,可以包含在样式表和脚本标记中。
Codekit 项目设置
Bower 资源:
我目前在项目之外全局存储这些:
~/bower_components/twbs-bootstrap-sass/vendor/assets/stylesheets
因为 CodeKit 支持指南针,我的 config.rb 文件中有这个:
add_import_path "~/bower_components/twbs-bootstrap-sass/vendor/assets/stylesheets"
项目结构
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
styles.scss 的内容
@import "modules/bootstrap-customizations"; # local customizations
@import "bootstrap/variables";
@import "bootstrap/mixins";
... # load bootstrap files as required
@import "bootstrap/wells";
系统设置:
- 系统:OS X 10.9
- 节点 - v0.10.32
- npm - v2.1.7
- zsh - zsh 5.0.7 (x86_64-apple-darwin13.4.0)
node 安装了 homebrew 的 brew install node 并且似乎工作正常。
我的尝试
我已经阅读了这些页面:
- 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
我多次尝试创建webpack.config.js 文件,我最近的尝试是这个的几个版本:
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 错误
当我运行 webpack 时,我得到了这个:
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 错误
我在尝试npm install bootstrap-sass 时遇到错误,并且在寻找解决方案时没有任何运气。我什至不确定我是否需要这个模块。
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
混乱的来源
对我来说,webpack 最令人困惑的部分是:
- 应该在哪里添加
require("bootstrap-sass-webpack")之类的内容 - 是在webpack.config.js文件中,还是在js/main.js文件中? - 这样的模块是否应该在使用
npm install安装后立即提供给 webpack? - 我认为我应该这样做
npm install webpack -g以便全局安装 webpack,并为其他模块使用npm install而不使用-g。但是,我没有看到在我的项目中创建任何node_modules文件夹。不应该有吗? - 如何为
require("bootstrap-sass-webpack")等内容确定/指定搜索路径?
我应该安装哪些节点模块才能做到这一点?我的webpack.config.js 应该是什么样子?
【问题讨论】:
-
我有一个非常相似的配置,我使用的是基于 gulp 的 exlir,但它调用了 webpack 加载机制。我无法让 bootstrap-sass-webpack 编写任何资产文件,除了显示它们捆绑在一起时称为“file.css”、“file.wof”。没有任何内容写入磁盘。
标签: coffeescript sass npm webpack