mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-03 13:13:10 +00:00
feature(webpack) split config to: js, html and css
This commit is contained in:
parent
3b17a16217
commit
1e716ef64f
5 changed files with 220 additions and 171 deletions
72
.webpack/css.js
Normal file
72
.webpack/css.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const {
|
||||
basename,
|
||||
extname,
|
||||
join,
|
||||
} = require('path');
|
||||
|
||||
const {env} = process;
|
||||
const isDev = env.NODE_ENV === 'development';
|
||||
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
|
||||
const extractCSS = (a) => new ExtractTextPlugin(`${a}.css`);
|
||||
const extractMain = extractCSS('[name]');
|
||||
|
||||
const cssNames = [
|
||||
'nojs',
|
||||
'view',
|
||||
'config',
|
||||
...getCSSList('columns'),
|
||||
];
|
||||
|
||||
const cssPlugins = cssNames.map(extractCSS);
|
||||
|
||||
const plugins = [
|
||||
...cssPlugins,
|
||||
extractMain,
|
||||
];
|
||||
|
||||
const rules = [{
|
||||
test: /\.css$/,
|
||||
exclude: /css\/(nojs|view|config|columns.*)\.css/,
|
||||
use: extractMain.extract([
|
||||
'css-loader?minimize',
|
||||
]),
|
||||
},
|
||||
...cssPlugins.map(extract), {
|
||||
test: /\.(png|gif|svg|woff|woff2|eot|ttf)$/,
|
||||
loader: 'url-loader?limit=50000',
|
||||
}];
|
||||
|
||||
module.exports = {
|
||||
plugins,
|
||||
module: {
|
||||
rules,
|
||||
},
|
||||
};
|
||||
|
||||
function getCSSList(dir) {
|
||||
const base = (a) => basename(a, extname(a));
|
||||
const addDir = (name) => `${dir}/${name}`;
|
||||
const rootDir = join(__dirname, '..');
|
||||
|
||||
return fs.readdirSync(`${rootDir}/css/${dir}`)
|
||||
.map(base)
|
||||
.map(addDir);
|
||||
}
|
||||
|
||||
function extract(extractPlugin) {
|
||||
const {filename} = extractPlugin;
|
||||
const loader = isDev ? 'css-loader' : 'css-loader?minimize';
|
||||
|
||||
return {
|
||||
test: RegExp(`css/${filename}`),
|
||||
use: extractPlugin.extract([
|
||||
loader
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue