码迷,mamicode.com
首页 > Web开发 > 详细

js文件外打包的简单使用

时间:2019-06-08 13:24:06      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:err   depend   require   config   conf   filename   word   src   load   

环境

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

文件结构

1.png
│  package.json
│  webpack.config.js
│
└─src
    │  app.js
    │
    └─css
            t.css

package.json(依赖)

{
  "name": "loader",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^2.1.1",
    "style-loader": "^0.23.1",
    "webpack": "^4.33.0",
    "webpack-cli": "^3.3.3"
  }
}

打包webpack配置

loader顺序必须是 style-css 再到 css-loader
file-loader

url-loader
const path = require(path);
module.exports = {
    entry: {
        app: ./src/app.js
    },
    output: {
        filename: "bundle.js",
        path: path.join(path.resolve(__dirname), dist)
    },
    mode: "development",
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
            },
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"] 
            }
        ]
    }
};

 

 

 

js文件外打包的简单使用

标签:err   depend   require   config   conf   filename   word   src   load   

原文地址:https://www.cnblogs.com/heidekeyi/p/10990357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!