0

我有一个src/styles/main.scss文件,我想将其转换为build/styles/main.css然后在index.html中使用它。

我一直在尝试使用文本提取器插件设置 webpack,但无法达到最终结果。

这是我的目录结构:

project
 // build needs to be generated, as of now only js folder with index.js is generated
 - build
 - src
   - styles
     - main.scss
     - components
       - header.scss
   - js
     - stores
     // some other files
 - webpack.config.js

webpack.config.js

const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require('path');

const BUILD_DIR = path.resolve(__dirname, 'build/js');
const APP_DIR = path.resolve(__dirname, 'src');

const config = {
  devtool: 'eval-source-map',
  entry: {
    "index": APP_DIR + '/js/index.jsx'
  },
  output: {
    path: BUILD_DIR,
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        include: APP_DIR,
        exclude: /node_modules/,
        use: ExtractTextPlugin.extract(
          'style-loader', // backup loader when not building .css file
          'css-loader!sass-loader'
        )
      },
      {
        test: /\.(jsx|js)?/,
        exclude: /node_modules/,
        include: APP_DIR,
        loader: 'babel-loader'
      }
    ]
  },
  resolve: {
    extensions: [".js", ".jsx"]
  },
  plugins: [
    new ExtractTextPlugin("build/styles/main.css")
  ]
};

module.exports = config;
4

0 回答 0