0

I'm trying to create a super simple webpack set up to create the css from sass

I have the files:

index.html
entry.js
package.json
webpack.config.js
css
-app.scss

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>

<script type="text/javascript" src="bundle.js" charset="utf-8"></script>
</body>

</html>

entry.js:

require('./css/app.scss');

package.json:

{
  "name": "ls",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer-loader": "^3.2.0",
    "css-loader": "^1.0.0",
    "node-sass": "^4.9.2",
    "postcss-loader": "^2.1.6",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.21.0",
    "svg-sprite-loader": "^3.8.0",
    "ts-loader": "^4.4.2",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  }
}

webpack.config.js:

module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            {
                test: /\.scss$/,
                use: [ 'style-loader','css-loader','postcss-loader' ]
            }
        ]
    }
};

app.scss:

*{
  color: red;
}

If I run npm start I get the error Error: Cannot find module 'webpack'

How do I set this up to output the css from the app.scss file

UPDATE

I installed webpack and now I'm getting the following error

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).
2
  • install webpack: npm install --save-dev webpack. You are missing it. Commented Aug 2, 2018 at 15:43
  • Now I'm getting something completely different - I have updated my question Commented Aug 2, 2018 at 15:53

1 Answer 1

1
module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [ 'style-loader','css-loader','postcss-loader' ]
            }
        ]
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.