我正在使用 webpack 和 sass-loadercustom.css
在我的公共目录中生成一个文件。我的 webpack.config 文件有以下内容:
// webpack.config.js
var ExtractTextPlugin = require("extract-text-webpack-plugin");
...
if(process.env.NODE_ENV === 'development'){
var loaders = ['react-hot','babel']
} else {
var loaders = ['babel']
}
module.exports = {
devtool: 'eval',
entry: './app-client.js',
output: {
path: __dirname + '/public/dist',
filename: 'bundle.js',
publicPath: '/dist/'
},
module: {
loaders: [{
test: /\.js$/,
loaders: loaders,
exclude: /node_modules/
},
// Extract SCSS
**{ test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!autoprefixer-loader!sass-loader") },]**,
include: __dirname + '/src/sass'
},
plugins: [
new ExtractTextPlugin("./public/css/style.css", {allChunks: false})
]
};
在 .views/index.html 文件中调用 css:
<link href="/css/custom.css" rel="stylesheet">
我的 package.json 中的开发脚本是:
"webpack-dev-server": "NODE_ENV=development PORT=8080 webpack-dev-server --content-base public/ --hot --inline --devtool inline-source-map --history-api-fallback",
"development": "cp views/index.html public/index.html && NODE_ENV=development webpack && npm run webpack-dev-server"
在./components/App.js
我有:
//stylesheets
import scss from 'custom.scss'
但我收到以下错误:
RROR in ./components/App.js
Module not found: Error: Cannot resolve module 'custom.scss' in /Users/koko1/apps/bamba-2017/components
@ ./components/App.js 38:18-40