【发布时间】:2017-03-26 14:06:12
【问题描述】:
我想将 LESS 文件编译为普通 CSS,然后将其添加到 /build 文件夹,但出现错误:
(function (exports, require, module, __filename, __dirname) { body {
^
SyntaxError: Unexpected token {
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/charisse/react/wanderlust/webpack.config.js:3:12)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
我知道错误来自 LESS 文件,但我不知道如何解决?
body {
background: yellow;
}
我已经按照教程进行操作,webpack.config.js 的构建方式似乎几乎相同:
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var Less = require('./app/css/styles.less');
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './app/index.html',
inject: 'body'
});
var ExtractTextPluginConfig = new ExtractTextPlugin('./build/styles.css');
module.exports = {
entry: './app/js/index.js',
output: {
path: __dirname + '/build',
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.less$/,
exclude: /(node_modules)/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer!less-loader')
}
]
},
plugins: [ HtmlWebpackPluginConfig, ExtractTextPluginConfig]
}
像'style-loader', 'css-loader'和style-loader!css-loader这样实现的加载器之间也有什么区别吗?
是否也可以只将编译后的 LESS 文件注入到位于 /build 文件夹中的 index.html 中?
【问题讨论】: