环境

node + yarn + webpack4.0 + webpack-cli + style-loader css-loader

文件结构

│  package.json
│  webpack.config.js
│  yarn.lock
│
├─dist
│      bundle.js
│      index.html
│
├─node_modules ...(太多了,省略)
└─src
    ├─css
    │      css.css
    │
    └─js
            app.js

package.json(依赖)

{
  "name": "demo_exclude_js_resource",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "css-loader": "^2.1.1",
    "style-loader": "^0.23.1",
    "webpack": "^4.33.0",
    "webpack-cli": "^3.3.3"
  }
}

打包webpack配置

const path = require('path');

module.exports = {
    entry: {
        app: './src/js/app.js'
    },
    output: {
        filename: "bundle.js",
        path: path.join(path.resolve(__dirname), 'dist')
    },
    mode: "development",
    module: {
        rules: [{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']//两个loader的顺序不能弄错
        }]
    }
}

其他一些文件说明

app.js

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

index.html:使用了一个h1标签,script中引入打包后的js文件(打包后出现:dist/bundle.js)

css.css:给h1标签添加背景颜色和样式

打包

npx webpack

打包完成后运行index.html就可以看到h1标签的样式是css.css中设置的样式

loader__demo_css的更多相关文章

随机推荐

  1. leetcode 114.Flatten Binary Tree to Linked List (将二叉树转换链表) 解题思路和方法

    Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 ...

  2. 从零单排入门机器学习:Octave/matlab的经常使用知识之矩阵和向量

    Octave/matlab的经常使用知识之矩阵和向量 之前一段时间在coursera看了Andrew ng的机器学习的课程,感觉还不错.算是入门了.这次打算以该课程的作业为主线,对机器学习基本知识做一 ...

  3. The return type is incompatible with JspSourceDependent.getDependants():JasperException问题分析与解决方法

    Linux下基于JSP的报表集成到项目中后,显示不出来,查看tomcat的日志.有例如以下报错信息: The return type is incompatible with JspSourceDep ...

  4. Swift 进阶

    iOS开发系列--Swift进阶 2015-09-21 00:01 by KenshinCui, 3072 阅读, 12 评论, 收藏, 编辑 概述 上一篇文章<iOS开发系列--Swift语言 ...

  5. LeetCode 168. Excel Sheet Column Title (Excel 表格列名称)

    Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...

  6. 更改App.config里的值并保存

    using System; using System.Collections.Generic; using System.Configuration; using System.IO; using S ...

  7. Unable to update auto-refresh reference 'microsoft.codedom.providers.dotnetcompilerplatform.dll'.

    Unable to update auto-refresh reference 'microsoft.codedom.providers.dotnetcompilerplatform.dll'. Ca ...

  8. luogu 1045 麦森数

    题目大意: 从文件中输入P(1000<P<3100000),计算2^P−1的位数和最后500位数字(用十进制高精度数表示) 思路: 一道高精度练习题 其中位数是一个结论 位数=[P*log ...

  9. 解决openresty http客户端不支持https的问题

    OpenResty默认没有提供Http客户端,需要使用第三方提供:当然我们可以通过ngx.location.capture 去方式实现,但它只能发送一个子请求. 第三方基本是以lua-resty-ht ...

  10. cf2.25

    T1 题意:判断给出的数中有多少不同的大于的数. content:傻逼题,5min手速 T2 题意:给出p.y,输出y~p+1中最大一个不是2-p的倍数的数. content:答案很简单,但是很难想到 ...