json Webpack 4 config.js(SCSS到CSS和Babel)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json Webpack 4 config.js(SCSS到CSS和Babel)相关的知识,希望对你有一定的参考价值。

/* === dont forget to import scss to main.js file === */
/* ===> import './main.scss'; <=== */

var path = require("path");

module.exports = {
  entry: "./main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
    publicPath: "/dist"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: "babel-loader",
          options: { presets: ["es2015"] }
        }
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: "style-loader" // creates style nodes from JS strings
          },
          {
            loader: "css-loader" // translates CSS into CommonJS
          },
          {
            loader: "sass-loader" // compiles Sass to CSS
          }
        ]
      }
    ]
  }
};
{
  "name": "webpack-sass",
  "version": "1.0.0",
  "scripts": {
    "start": "webpack-dev-server --open --mode development",
    "build": "webpack -p"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "css-loader": "^0.28.11",
    "node-sass": "^4.8.3",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.20.3",
    "webpack": "^4.5.0",
    "webpack-cli": "^2.0.14",
    "webpack-dev-server": "^3.1.1"
  }
}

以上是关于json Webpack 4 config.js(SCSS到CSS和Babel)的主要内容,如果未能解决你的问题,请参考以下文章

如何通过 vue.config.js webpack config 将 JSON 文件写入 dist 文件夹?

在 webpack.config.js 中获取当前的 `--mode`

如何通过新的 @angular/cli v7 angular.json 或 custom-webpack.config.js 添加额外的 postcss 插件?

webpack.config.js配置文件

webpack前端构建工具学习总结之webpack.config.js配置文件

在 nextJS (next.config.js) 中设置 webpack 配置