Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Less 网页包的加载程序不工作_Less_Webpack - Fatal编程技术网

Less 网页包的加载程序不工作

Less 网页包的加载程序不工作,less,webpack,Less,Webpack,我正在尝试使用webpack。我无法为网页包设置较少的加载程序。当我启动webpack时,它会编译js文件,但不会编译得更少。编译后,我在dist文件夹中只看到“index.html”和“app.js” My webpack.config.js: var webpack = require('webpack'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var HtmlWebpackPlugin = requ

我正在尝试使用webpack。我无法为网页包设置较少的加载程序。当我启动webpack时,它会编译js文件,但不会编译得更少。编译后,我在dist文件夹中只看到“index.html”和“app.js”

My webpack.config.js:

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        'app': './src/scripts/app'
    },
    output: {
        path: './dist',
        filename: `/app.js`,
        chunkFilename: "[id].js"
    },
    resolve: {
        modulesDirectories: ['bower_components', 'node_modules', './src'],
        fallback: ['./public']
    },
    module: {
        loaders: [
            {
                test: /\.less$/,
                loader: ExtractTextPlugin.extract(
                    'css?sourceMap!' +
                    'less?sourceMap'
                )
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin(`[name].css`, {
            allChunks: true
        }),
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ]
};
我的项目结构:

src
 |-index.html
 |--scripts
 | |-app.js
 |--styles
 | |-app.less

Webpack扫描源代码,查找
require
语句以查找文件。确保在代码中包含
require('my.less')
或类似内容


[更新]Webpack还了解ES6模块语法,因此如果您喜欢这种样式,导入'my.less'也会起作用。

对于Webpack,您需要在javascript代码中找到
所需的.less文件('my.less')
。是吗?这很有效。非常感谢。