简体   繁体   English

如何在npm start中使用编译ES6(反应)组件和基础sass

[英]How to use compile ES6 (react) components and foundation sass with npm start

I followed this tutorial to setup a react project and I thought I nailed it. 我按照本教程设置了一个React项目,并以为自己钉上了它。 After installing everything works as it should. 安装后,一切正常。

But I have to create a website that uses foundation as a front-end lib. 但是我必须创建一个使用Foundation作为前端库的网站。 The tutorial I linked above runs server.js when I run npm start but foundation-cli uses the same command for compiling all foundation sass code to css. 我上面链接的教程在运行npm start时运行server.js,但是foundation-cli使用相同的命令将所有基础sass代码编译为css。

At the moment when I run npm start it only runs react and not foundation. 在我运行npm start的那一刻,它只运行react而不是基础。 How can I run foundation too? 我也如何经营基金会? can I make it so that it'll automatically run both? 我可以使其自动运行吗?

Since you are already using Webpack, I would suggest you to use one of the loaders for it and compile your CSS with it. 由于您已经在使用Webpack,因此建议您使用其中一个加载程序,并使用它来编译CSS。 This one seems like it can do that for you. 这一次似乎是它可以为你做的。

This is not tested, but I assume you can add it to your Webpack config like this: 这未经测试,但我假设您可以将其添加到Webpack配置中,如下所示:

// be sure to install it with
// npm install sass-loader node-sass --save-dev

const path = require('path');

module.exports = {
  context: path.join(__dirname, 'src'),
  entry: [
    './main.js',
  ],
  output: {
    path: path.join(__dirname, 'www'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          'babel-loader',
        ],
      },
      {
        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
        }
      }
    ],
  },
  resolve: {
    modules: [
      path.join(__dirname, 'node_modules'),
    ],
  },
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM