SASS を CSS にコンパイルしようとしましたが、うまくいきません。Webpack は css ファイルを生成しません。このプロジェクトを試してみたところ、うまくいったので、おそらくwebpack構成の何かが間違っています。
webpack.config.js
const BowerWebpackPlugin = require("bower-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require("path");
const sassLoaders = [
"css-loader",
"sass-loader?indentedSyntax=sass&includePaths[]=" + path.resolve(__dirname, "./src"),
];
const config = {
entry: './src/script/index.jsx',
output: {
filename: 'bundle.js',
path: path.join(__dirname, "./build"),
publicPath: 'http://localhost:8090/assets',
},
devtool: 'eval-source-map',
module: {
loaders: [
{
test: /\.js[x]?$/, exclude: /node_modules/, loader: 'babel-loader'
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", sassLoaders.join("!")),
},
]
},
plugins: [
new BowerWebpackPlugin(),
new ExtractTextPlugin("[name].css"),
],
externals: {
'react': 'React'
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss'],
modulesDirectories: ["src", "node_modules", "bower_components"],
}
};
module.exports = config;
パッケージ.json
{
"scripts": {
"start": "npm run serve | npm run dev",
"serve": "./node_modules/.bin/http-server -p 8080",
"dev": "webpack-dev-server --progress --colors --port 8090"
},
"name": "name",
"version": "1.0.0",
"description": "internal evidence application",
"main": "index.js",
"author": "author",
"license": "ISC",
"dependencies": {
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"extract-text-webpack-plugin": "^0.8.2",
"react": "^0.13.3"
},
"devDependencies": {
"babel-loader": "^5.3.2",
"bower-webpack-plugin": "^0.1.8",
"css-loader": "^0.16.0",
"http-server": "^0.8.0",
"jsx-loader": "^0.13.2",
"node-sass": "^3.2.0",
"path": "^0.11.14",
"sass-loader": "^2.0.1",
"style-loader": "^0.12.3",
"webpack": "^1.11.0",
"webpack-dev-server": "^1.10.1"
}
}
プロジェクト構造
webpack-dev-server の出力
...
Hash: d8029817acd9fe21718c
Version: webpack 1.11.0
Time: 3884ms
Asset Size Chunks Chunk Names
bundle.js 871 kB 0 [emitted] main
chunk {0} bundle.js (main) 211 kB [rendered]
[0] ./src/script/index.jsx 274 bytes {0} [built]
[2] ./src/script/hello.jsx 456 bytes {0} [built]
[3] jquery (bower component) 45 bytes {0} [built]
[4] ./bower_components/jquery/dist/jquery.js 210 kB {0} [built]
+ 1 hidden modules
webpack: bundle is now VALID.