Answer the question
In order to leave comments, you need to log in
Why does webpack create a wrapper function in the collected css?
I'm migrating a project from Gulp to webpack.
I set up the assembly of styles (I use Sass).
As an entry point I use the index.scss file, where the rest of the style modules are imported:
const entry = [
"./static/styles/index.scss"
];
output: {
path: __dirname + "/public",
publicPath: "/",
filename: "[name].css"
},
loaders: [
{
test: /\.(scss|css)$/,
loader: "style!css!sass!resolve-url-loader"
},
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ } // и так далее
// webpack.config.js
"use strict";
const NODE_ENV = process.env.NODE_ENV || "development";
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const entry = [
"./static/styles/index.scss"
//__dirname + "/static/fonts/"
];
module.exports = {
entry,
//target: "web",
output: {
path: __dirname + "/public",
publicPath: "/",
filename: "[name].css"
},
module: {
loaders: [
{
test: /\.(scss|css)$/,
loader: "style!css!sass!resolve-url-loader"
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
loader: "file?name=fonts/[name].[ext]"
}
]
},
watch: NODE_ENV == "development",
devtool: NODE_ENV == "development" ? "source-map" : null,
plugins: [
new webpack.DefinePlugin({
NODE_ENV: NODE_ENV
}),
new ExtractTextPlugin("main.css")
],
externals: [nodeExternals()]
}
Answer the question
In order to leave comments, you need to log in
concepts :
CSS styles or any other resource (in the Webpack concept) is collected for a JS application.
When dealing with only one CSS, there is no point in using Webpack.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question