我不确定为什么会收到此错误。我查看了一些LESS文档,语法似乎正确。我正在使用webpack和一些加载器:
这是我的webpack.config.js:
var path = require('path')
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: [
'./app/index.js'
],
output: {
path: './public/js',
filename: 'main.js',
},
devtool: 'eval',
debug: true,
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.jsx$/, loaders: ['react-hot','jsx-loader'], include: path.join(__dirname, 'app') },
{ test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css!less'},
{ test: /\.css$/, exclude: /node_modules/, loader: 'style-loader!css-loader' }
]
},
plugins: [
new ExtractTextPlugin('style.css', {
allChunks: true
}),
new webpack.optimize.CommonsChunkPlugin('common.js'),
]
};
当我想在手表模式下运行时,我会使用这个。下面的webpack配置是生成错误的配置。
var Webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = require("./webpack.config.js");
var port = process.env.WEBPACK_PORT || 8080;
var host = process.env.HOST || 'localhost';
config.entry.unshift(
"webpack-dev-server/client?http://" + host + ":" + port,
"webpack/hot/only-dev-server" // only prevents reload on syntax errors
);
config.plugins = [
new ExtractTextPlugin("style.css", {
allChunks: true
}),
new Webpack.HotModuleReplacementPlugin(),
];
config.module.loaders = [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css!less'},
{ test: /\.css$/, exclude: /node_modules/, loader: 'style-loader!css-loader' }
];
// dev server for react hot loader
config.devServer = {
publicPath: "/js/",
filename: 'main.js',
contentBase: "./public",
hot: true,
inline: true,
lazy: false,
quiet: true,
noInfo: true,
headers: {"Access-Control-Allow-Origin": "*"},
stats: {colors: true},
host: "0.0.0.0",
port: port
};
module.exports = config;
错误:
/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/lib/transformation/file/index.js:664
[1] throw err;
[1] ^
[1]
[1] SyntaxError: /Users/bli1/Development/Javascript/ReviewWeb/app/styles/index.less: Unexpected token (1:0)
[1] > 1 | @import "generic.less";
[1] | ^
[1] 2 | @import "buttons.less";
[1] 3 | @import "register.less";
[1] 4 |
[1] at Parser.pp.raise (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
[1] at Parser.pp.unexpected (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
[1] at Parser.pp.parseDecorator (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:170:10)
[1] at Parser.pp.parseDecorators (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:156:37)
[1] at Parser.pp.parseStatement (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:58:10)
[1] at Parser.parseStatement (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:621:22)
[1] at Parser.pp.parseTopLevel (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:30:21)
[1] at Parser.parse (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:70:17)
[1] at Object.parse (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/index.js:45:50)
[1] at Object.exports.default (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/lib/helpers/parse.js:36:18)
[1] 23 Oct 17:12:37 - [nodemon] app crashed - waiting for file changes before starting...