webpack.config.js代码
var path = require('path');
var webpack = require('webpack');
var distPath = path.join(__dirname, '/public/dist/');
module.exports = {
entry: {
a: './components/a.js',
b: './components/b.js'
},
output: {
path: distPath,
publicPath: "/public/dist/",
filename: '[name].js'
}
//plugins: plugins
};
a.js代码
require("c.js");
b.js代码
require("c.js");
c.js代码
var c = function(){
console.log('asdasd');
}
module.exports = c;
错误提示
Hash: 7d501d0a5c06770cc551
Version: webpack 1.13.1
Time: 47ms
Asset Size Chunks Chunk Names
a.js 1.57 kB 0 [emitted] a
b.js 1.57 kB 1 [emitted] b
+ 2 hidden modules
ERROR in ./components/b.js
Module not found: Error: Cannot resolve module 'c.js' in D:\luoo\nodejs\components
@ ./components/b.js 1:0-15
ERROR in ./components/a.js
Module not found: Error: Cannot resolve module 'c.js' in D:\luoo\nodejs\components
@ ./components/a.js 1:0-15
我想问为什么会有错误提示?
经验证发现如果 require
的不是路径而是用别名的方式就不会有错误提示。
求解惑!
写相对路径