M
M
ML2017-11-21 13:37:02
JavaScript
ML, 2017-11-21 13:37:02

Is it possible to do without manually embedding css styles in the DOM?

webpack config

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

module.exports = {
  entry: {
    app: './app.ts',
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js']
  },
  module: {
    loaders: [
      { test: /\.tsx?$/, loader: 'ts-loader' }
    ],
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      },
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [ 'css-loader', 'sass-loader' ]
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('app.css')
  ]
}

app.tshtml _
import 'app.css';
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/dist/app.css" type="text/css">
</head>
<body></body>
</html

Is it always necessary to manually include files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-11-21
@k12th

  1. Try the html-webpack-plugin, it includes all entries automatically and is quite flexible.
  2. In dev mode, it doesn't make sense to extract styles via ExtractTextPlugin (besides, it's not fast), just include them as import './app.scss'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question