webpack - Webpack sass 到 css 并保留文件夹结构
问题描述
我需要使用保留文件夹结构将 scss 文件转换为 css。例子:
/saas/plugins/plugin1/file1.scss
/saas/plugins/plugin2/fileA.scss
/saas/plugins/pluginC/file3.scss
/saas/template/template1.scss
/saas/folder1/style.scss
/saas/style.scss
编译后:
/css/plugins/plugin1/file1.css
/css/plugins/plugin2/fileA.css
/css/plugins/pluginC/file3.css
/css/template/template1.css
/css/folder1/style.css
/css/style.css
怎么做 ?
解决方案
webpack.config.js
const path = require('path');
module.exports = {
entry: [
__dirname + '/src/js/app.js',
__dirname + '/src/scss/app.scss'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/app.min.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [],
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: { outputPath: 'css/', name: '[name].min.css'}
},
'sass-loader'
]
}
]
}
};
包.json
{
"name": "...",
"version": "1.0.0",
"description": "...",
"private": true,
"dependencies": {},
"devDependencies": {
"file-loader": "^5.0.2",
"node-sass": "^4.13.1",
"sass-loader": "^8.0.2",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
},
"scripts": {
"build": "webpack --config webpack.config.js --mode='production'"
},
"keywords": [],
"author": "...",
"license": "ISC"
}
依赖项:
npm install --save-dev webpack webpack-cli file-loader node-sass sass-loader
如何运行 JS 和 SCSS 编译
npm run build
推荐阅读
- ibm-cloud - 原因:无法在 IBM Bluemix 中为 user.in 创建 git 帐户?
- ruby - Ruby 网络服务器 - 服务请求时回调
- linker - 如何在 Keil Scatter 加载描述文件中设置自定义内存区域
- websocket - Redux Observables 的 RXJS6 Websocket 主题订阅问题
- java - hibernate手动控制对象构造
- php - 我无法在不同页面中使用两个不同的搜索栏请帮助解决此问题
- jquery - 从 td 中的动态表中获取文本框 id
- android - 如何在 Ubuntu 16.04 上的 Android Studio 3.2 版本中打开 AVD 管理器?
- database - How to sort data from database in laravel html
- ios - 如何获取对象的值