来自Fullstack.io: create yelp clone的教程
在我的webpack.config.js文件中:
const webpack = require('webpack');
const fs = require('fs');
const path = require('path'),
join = path.join,
resolve = path.resolve;
const root = resolve(__dirname);
const src = join(root, 'src');
const modules = join(root, 'node_modules');
const dest = join(root, 'dist');
const NODE_ENV = process.env.NODE_ENV;
const isDev = NODE_ENV === 'development';
const getConfig = require('hjs-webpack');
var config = getConfig({
isDev: isDev,
in: join(src, 'app.js'),// entry point file
out: dest,
// blow away any previously built files before it starts building new ones
clearBeforeBuild: true
});
config.module.loaders.push({
test: /\.css$/,
include: [modules],
loader: 'style!css'
})
module.exports = config;
运行开发人员时。服务我得到以下错误:
TypeError: Cannot read property 'push' of undefined
at Object.<anonymous> (E:\projects\React\yelpReact\webpack.config.js:90:22)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\projects\React\yelpReact\node_modules\hjs-webpack\bin\hjs-dev-server.js:17:12)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
Failed to load webpack config, please use like this
hjs-dev-server.js webpack.config.js
原来 config.module.loaders返回null ,我在这里到底在做什么错,我从没使用过“ hjs-webpack”,感谢任何帮助
答案 0 :(得分:1)
Cannot read property 'push' of undefined
提示config.module.loaders
未定义。
这是一个webpack配置,在webpack配置中,加载程序位于module.rules
中,我认为module.loaders
无法识别(并且
因此,getConfig
可能不会返回。)
我建议您尝试将modules
替换为rules
,如下所示:
config.module.rules.push({
test: /\.css$/,
include: [modules],
loader: 'style!css'
});
答案 1 :(得分:0)
WP加载器驻留在rules
子数组中。
此外-对hjs-webpack
中的导出进行的快速检查显示,实际上loaders
对象上没有module
属性。
因此-您应按以下方式更新代码:
config.module.loaders.push({
test: /\.css$/,
include: [modules],
loader: 'style!css'})