Javascript 为什么在运行webpack时发生模块生成错误?
发生此错误时,我正在编写加载程序:Javascript 为什么在运行webpack时发生模块生成错误?,javascript,webpack,Javascript,Webpack,发生此错误时,我正在编写加载程序: ERROR in ./src/components/notFound.vue Module build failed (from ./loader/cssExchangeLoader.js): /Users/laiyinan/Project/前端开发/blog/loader/cssExchangeLoader.js:3 export default function(source){ ^^^^^^ SyntaxError: Unexpected token
ERROR in ./src/components/notFound.vue
Module build failed (from ./loader/cssExchangeLoader.js):
/Users/laiyinan/Project/前端开发/blog/loader/cssExchangeLoader.js:3
export default function(source){
^^^^^^
SyntaxError: Unexpected token export
装载机(全部):
webpack.config(部分内容):
为什么在运行webpack时发生模块生成错误?如何修复它?提前谢谢 默认情况下,Webpack(实际上不是Webpack本身,而是Node.js)只支持CJS导入。该代码将在以下情况下起作用:
var loaderUtils = require('loader-utils');
module.exports = function(source){
let options = loaderUtils.getOptions(this);
console.log(options);
console.log(source.substr(0,10));
return `export default ${JSON.stringify(source)}`;
}
{
test: /(\.css$)|(\.scss$)|(\.vue$)/,
use: [
{
loader: path.resolve(root,'loader/cssExchangeLoader.js'),
options: {
target: 'red',
alternative: 'green'
}
}
],
exclude: [/node_modules/,/loader/]
}
var loaderUtils = require('loader-utils');
module.exports = function(source){
let options = loaderUtils.getOptions(this);
console.log(options);
console.log(source.substr(0,10));
return `export default ${JSON.stringify(source)}`;
}