Created
March 4, 2019 19:48
-
-
Save koyta/0520d0f1b13e8ede98ea64e505e97381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const md5File = require('md5-file'); | |
const path = require('path'); | |
const sass = require('node-sass'); | |
const ignoreStyles = require('ignore-styles'); | |
const register = ignoreStyles.default; | |
const extensions = ['.gif', '.jpeg', '.jpg', '.png', '.svg']; | |
register(ignoreStyles.DEFAULT_EXTENSIONS, (mod, filename) => { | |
if (!extensions.find(f => filename.endsWith(f))) { | |
return ignoreStyles.noOp(); | |
} else { | |
const hash = md5File.sync(filename).slice(0, 8); | |
const bn = path.basename(filename).replace(/(\.\w{3})$/, `.${hash}$1`); | |
mod.exports = `/static/media/${bn}`; | |
} | |
}); | |
function processSass(data, filename) { | |
var result; | |
result = sass.renderSync({ | |
data: data, | |
file: filename, | |
}).css; | |
return result.toString('utf8'); | |
} | |
require('@babel/polyfill'); | |
require('@babel/register')({ | |
ignore: [/\/(build|node_modules)\//], | |
presets: ['@babel/preset-env', '@babel/preset-react'], | |
plugins: [ | |
'@babel/plugin-proposal-object-rest-spread', | |
'@babel/plugin-syntax-dynamic-import', | |
'dynamic-import-node', | |
'react-loadable/babel', | |
[ | |
'css-modules-transform', | |
{ | |
extensions: ['.css', '.scss', '.sass'], | |
preprocessCss: processSass, | |
generateScopedName: '[local]__[hash:base64:3]', | |
}, | |
], | |
], | |
}); | |
require('./server'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment