如何在webpack中编译更少?

时间:2018-05-02 12:55:21

标签: webpack less

我要编译文件夹中的所有 .less 文件,以便在我运行 npm start 时通过 link 标记加载它们。没有生成css文件。当我运行 npm start 时,我的项目开始没有,没有带 .less 关键字的消息。我浏览了webpack教程,无法设置较少的编译环境。

的package.json

{
 "name": "webpack-demo",
 "description": "",
 "private": true,
 "scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "build": "webpack --config webpack.prod.js",
   "watch": "webpack --watch",
   "start": "webpack-dev-server --open --config webpack.dev.js",
   "server": "node server.js",
   "webpack": "webpack"
 },
 "keywords": [],
 "author": "",
 "license": "ISC",
 "devDependencies": {
   "clean-webpack-plugin": "^0.1.19",
   "css-loader": "^0.28.11",
   "express": "^4.16.3",
   "extract-text-webpack-plugin": "^3.0.2",
   "file-loader": "^1.1.11",
   "html-webpack-plugin": "^3.2.0",
   "less": "^3.0.1",
   "less-loader": "^4.1.0",
   "style-loader": "^0.21.0",
   "webpack": "^4.6.0",
   "webpack-cli": "^2.0.15",
   "webpack-dev-middleware": "^3.1.2",
   "webpack-dev-server": "^3.1.3",
   "webpack-merge": "^4.1.2"
 },
 "dependencies": {
   "angular": "^1.6.10"
 }

}

webpack.dev.js

const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = merge(common, {
  mode: 'development',
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './dist'
  },
  module: {
       rules: [{
         test: /\.less$/,
         use: [{
           loader: 'style-loader' // creates style nodes from JS strings
         }, {
           loader: 'css-loader' // translates CSS into CommonJS
         }, {
           loader: 'less-loader' // compiles Less to CSS
         }]
}]
  }
});

0 个答案:

没有答案