js文件外打包的简单使用
Posted heidekeyi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js文件外打包的简单使用相关的知识,希望对你有一定的参考价值。
环境
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文件外打包的简单使用的主要内容,如果未能解决你的问题,请参考以下文章