wchbrad / vue-easy-tree

A tree component based on vue2.x that supports a small amount of data or a large amount of data, multiple functions, and virtual scrolling.
MIT License
130 stars 40 forks source link

scss如何转成less使用 #51

Closed DTZHY closed 4 months ago

DTZHY commented 4 months ago

原来的项目使用的是less预处理,不想在多加一个scss来预处理,担心会有兼容冲突问题,怎么实现使用less来使用这个插件呢

DTZHY commented 4 months ago

已解决

rocwong-cn commented 2 months ago

请问如何解决的?

rocwong-cn commented 2 months ago

vue-easy-tree.css.zip

我也解决了,把作者的代码clone下来,改了点webpack配置,构建出来了一个css文件,直接放到项目下了。

mini-css-extract-plugin 要使用 v0.9.0 完整的webpack配置:

var path = require("path");
var webpack = require("webpack");
const NODE_ENV = process.env.NODE_ENV;
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  // entry: './src/main.js',
  mode: NODE_ENV,
  entry: {
    main: NODE_ENV === "development" ? "./src/main.js" : "./index.js",
    styles: './src/assets/index.scss'
  },
  output: {
    path: path.resolve(__dirname, "./dist"),
    publicPath: "/dist/",
    filename: "[name].js",
    library: "vue-easy-tree",
    libraryTarget: "umd",
    umdNamedDefine: true,
  },
  plugins: [
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin({
      filename: "[name].css",
    }),
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["vue-style-loader", "css-loader"],
      },
      {
        test: /\.(ttf|woff|eot|svg)$/,
        use: [
          {
            loader: "file-loader",
            options: {
              outputPath: "fonts",
            },
          },
        ],
      },
      {
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.sass$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader?indentedSyntax'
        ]
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            scss: ["vue-style-loader", "css-loader", "sass-loader"],
            sass: [
              "vue-style-loader",
              "css-loader",
              "sass-loader?indentedSyntax",
            ],
          },
          // other vue-loader options go here
        },
      },
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: "file-loader",
        options: {
          name: "[name].[ext]?[hash]",
        },
      },
    ],
  },
  resolve: {
    alias: {
      vue$: "vue/dist/vue.esm.js",
    },
    extensions: ["*", ".js", ".vue", ".json"],
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true,
  },
  performance: {
    hints: false,
  },

  optimization: {
    minimizer: [new UglifyJsPlugin()],
  },
};

if (process.env.NODE_ENV === "production") {
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: '"production"',
      },
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true,
    }),
  ]);
} else {
  module.exports.devtool = "#source-map";
}

function resolve(dir) {
  return path.join(__dirname, "..", dir);
}