Skip to content

Instantly share code, notes, and snippets.

@abiral
Created March 9, 2018 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abiral/062e250af7457ee7974eb05d5d363fc5 to your computer and use it in GitHub Desktop.
Save abiral/062e250af7457ee7974eb05d5d363fc5 to your computer and use it in GitHub Desktop.
{
"name": "bundle-all",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.10",
"node-sass": "^4.7.2",
"sass-loader": "^6.0.7",
"copy-webpack-plugin": "^4.5.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"webpack": "^4.0.1",
"webpack-glob": "^2.0.2"
}
}
const glob = require("glob");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const getFileLists = (...data) => {
let ret = {};
for( [i, obj] of Object.entries(data) ){
let path = `${obj.base}${obj.src}`;
pathList = glob.sync(path);
for( [i, p] of Object.entries(pathList) ){
let key = obj.dest+p.split('/').slice(-1)[0];
if(typeof obj.ext != "undefined"){
key = key.replace(obj.src.split('.').slice(-1)[0].trim(),obj.ext);
}
if(typeof ret[key] == "undefined"){
ret[key] = [p];
}else{
ret[key].push(p);
}
}
}
return ret;
}
const stylesheets = {
base: './assets/src/scss/',
src: '*.scss',
dest:'./assets/build/css/',
'ext': 'css'
};
const scripts = {
base: './assets/src/js/',
src: '*.js',
dest:'/assets/build/js/'
};
let filesToTranspile = {};
filesToTranspile = getFileLists(scripts, stylesheets);
filesToTranspile['./assets/build/css/main.css'].push('./assets/src/css/style.css');
const mode = 'development';
module.exports = {
mode: mode,
entry: filesToTranspile,
output: {
path: __dirname,
filename: '[name]'
},
watch: true,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['es2015']
}
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
use: [
{ loader: 'css-loader', options: {
minimize: ((mode=='production')?true:false)
} },
{ loader : 'sass-loader', options: {
sourceMap: true,
outputStyle: 'expanded',
minimize: ((mode=='production')?true:false)
} }
]
})
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
use: [
{ loader: 'css-loader', options: {
minimize: ((mode=='production')?true:false)
} },
{ loader : 'sass-loader', options: {
sourceMap: true,
outputStyle: 'expanded',
minimize: ((mode=='production')?true:false)
} }
]
})
}
]
},
plugins: [
new ExtractTextPlugin({
filename: (getPath) => {
let path = getPath('[name]').replace('js','css').replace('scss', 'css');
return path
},
allChunks: true,
}),
new CopyWebpackPlugin([
{ from: './assets/src/img/', to: './assets/build/img/' },
{ from: './assets/src/fonts/', to: './assets/build/fonts/' }
])
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment