Commit f331b977 authored by 张俊's avatar 张俊

脚本第一版,完成对src文件夹内的scss文件做处理,并在对于目录生成同名css

parent c09e3bc8
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./src/index.js":
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/***/ (() => {
eval("var a = 1\n\n//# sourceURL=webpack://scss-to-css/./src/index.js?");
/***/ })
/******/ });
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./src/index.js"]();
/******/
/******/ })()
;
\ No newline at end of file
/**
* 读取一个目录中所有子目录和文件
*/
const fs = require('fs')
const path = require('path')
class File {
constructor(filename, name, ext, isFile, size, creeateTime, updateTime) {
this.filename = filename
this.name = name // 文件名
this.ext = ext // 后缀
this.isFile = isFile // 是否文件
this.size = size // 文件大小
this.creeateTime = creeateTime // 创建时间
this.updateTime = updateTime // 更新时间
}
static async getFile(filename) {
const stat = await fs.promises.stat(filename)
const { size, birthtime, mtime } = stat
let name = path.basename(filename),
ext = path.extname(filename),
isFile = stat.isFile(),
creeateTime = new Date(birthtime),
updateTime = new Date(mtime);
return new File(filename, name, ext, isFile, size, creeateTime, updateTime)
}
// 获取目录的所有子文件对象,如果是文件返回空数组
async getChildren() {
if (this.isFile) { return [] }
let dirArr = await fs.promises.readdir(this.filename);
dirArr = dirArr.map(fileName => {
const filename = path.resolve(this.filename, fileName)
return File.getFile(filename)
})
return Promise.all(dirArr)
}
// 获取文件内容, 如果是目录,返回null
async getContent(isBuffer = false) {
if (!this.isFile) { return null }
if (isBuffer) {
return await fs.promises.readFile(this.filename)
}
return await fs.promises.readFile(this.filename, 'utf-8')
}
}
async function readDir(dirname) {
const file = await File.getFile(dirname)
return await file.getChildren()
}
const dirname = path.resolve(__dirname, '../src')
console.log(readDir(dirname))
async function test() {
const dirname = path.resolve(__dirname, '../src')
const filename = path.resolve(__dirname, './index.js')
const dir = await File.getFile(dirname)
console.log('dir', await dir.getChildren())
const file = await File.getFile(filename)
console.log('file', file)
}
test()
\ No newline at end of file
/**
* 读取一个目录中所有子目录和文件
*/
const fs = require('fs')
const path = require('path')
var fileArr = []
var acceptFile = ['scss']
var getFile = async function(pathStr){
let dirArr = await fs.promises.readdir(pathStr);
console.log(dirArr);
dirArr.forEach(e => {
//文件夹
let str = pathStr+'/'+e
if(!isFile(str)){
getFile(str)
}else{
let fileType = str.split('.')[str.split('.').length-1]
if(acceptFile.indexOf(fileType)!==-1){
fileArr.push({
outputPath:pathStr+'/',
inputPath:str
})
}
}
});
}
var isFile = function(filename){
var stat = fs.lstatSync(filename);
var isFile = stat.isFile()
return isFile
}
module.exports = {
getFile,
fileArr,
}
getFile('./src')
// setTimeout(()=>{
// console.log(fileArr);
// },5000)
\ No newline at end of file
/**
* 读取一个目录中所有子目录和文件
*/
const fs = require('fs')
const path = require('path')
var fileArr = []
var acceptFile = ['scss']
var getFile = function(pathStr,cb){
fs.readdir(pathStr,function(err,dirArr){
console.log(dirArr);
dirArr.forEach(e => {
//文件夹
let str = pathStr+'/'+e
if(!isFile(str)){
getChildernFile(str)
}else{
let fileType = str.split('.')[str.split('.').length-1]
if(acceptFile.indexOf(fileType)!==-1){
fileArr.push({
outputPath:pathStr+'/',
inputPath:str
})
}
}
});
cb?cb():''
});
}
var getChildernFile = function(pathStr){
fs.readdir(pathStr,function(err,dirArr){
console.log(dirArr);
dirArr.forEach(e => {
//文件夹
let str = pathStr+'/'+e
if(!isFile(str)){
getFile(str)
}else{
let fileType = str.split('.')[str.split('.').length-1]
if(acceptFile.indexOf(fileType)!==-1){
fileArr.push({
outputPath:pathStr+'/',
inputPath:str
})
}
}
});
});
}
var isFile = function(filename){
var stat = fs.lstatSync(filename);
var isFile = stat.isFile()
return isFile
}
module.exports = {
getFile,
fileArr,
}
getFile('./src',function(){
console.log(fileArr);
})
// setTimeout(()=>{
// console.log(fileArr);
// },5000)
\ No newline at end of file
.aa{
height: 100px;
background-color: #fff;
}
\ No newline at end of file
.aaa {
width: 100px; }
.aaa{
width: 100px;
}
\ No newline at end of file
.bs {
color: #000; }
.bs{
color: #000;
}
\ No newline at end of file
.aa{
width: 100px;
.bb{
height: 100px;
}
}
\ No newline at end of file
.cc{
margin: 0;
.dd{
padding: 0;
}
}
\ No newline at end of file
var a = 1
\ No newline at end of file
.v-divider {
webkit-transform: scale(1, 0.5);
transform: scale(1, 0.5); }
.v-divider--vertical {
webkit-transform: scale(0.5, 1);
transform: scale(0.5, 1); }
.theme--light.v-divider {
background-color: #ebedf0;
border-width: 0;
height: 1px;
max-height: 1px; }
.theme--light.v-divider--vertical {
background-color: #ebedf0;
border-width: 0;
width: 1px;
max-width: 1px; }
@mixin scale($x,$y){
webkit-transform: scale($x,$y);
transform: scale($x,$y);
}
@mixin scaleX($val){
webkit-transform: scaleX($val);
transform: scaleX($val);
}
.v-divider{
@include scale(1,0.5)
&--vertical{
@include scale(0.5,1)
}
}
.theme--light{
&.v-divider{
background-color:#ebedf0;
border-width:0;
height: 1px;
max-height: 1px;
&--vertical{
background-color:#ebedf0;
border-width:0;
width: 1px;
max-width: 1px;
}
}
}
\ No newline at end of file
...@@ -2,6 +2,9 @@ const path = require('path'); ...@@ -2,6 +2,9 @@ const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const entry = require('webpack-glob-entry') const entry = require('webpack-glob-entry')
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries"); const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const {getFile,fileArr} = require('./readFile');
getFile('./src')
const baseConfig = { const baseConfig = {
module : { module : {
...@@ -20,15 +23,28 @@ const baseConfig = { ...@@ -20,15 +23,28 @@ const baseConfig = {
path: path.resolve(__dirname, './'), path: path.resolve(__dirname, './'),
}, },
} }
module.exports = [
{ var useArr = []
...baseConfig,
entry: entry('./src/*.scss'),
plugins: [ //暂时没想到好的办法处理异步递归完成的时间问题,延时5s进行打包
new FixStyleOnlyEntriesPlugin(), module.exports = new Promise((resolve,reject)=>{
new MiniCssExtractPlugin({ setTimeout(() => {
filename: 'css/[name].css' //css打包输出出口及文件名称 console.log(fileArr);
fileArr.forEach(e => {
useArr.push({
...baseConfig,
entry: entry(e.inputPath),
plugins: [
new FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin({
filename: e.outputPath+'/[name].css' //css打包输出出口及文件名称
})
],
}) })
], });
}
]; resolve(useArr)
\ No newline at end of file
}, 5000);
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment