Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from timneutkens/master
Browse files Browse the repository at this point in the history
Pull in latest changes
  • Loading branch information
timneutkens authored Feb 23, 2018
2 parents 355c700 + b6e1100 commit 010a644
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 108 deletions.
124 changes: 61 additions & 63 deletions lib/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ module.exports = async function() {
}

const extractSass = new ExtractTextPlugin({
filename: '[name].css',
disable: isDev
filename: '[name].css'
})

let config = {
Expand All @@ -80,7 +79,11 @@ module.exports = async function() {
modules: [path.join(__dirname, '../../node_modules'), 'node_modules']
},
resolveLoader: {
modules: [path.join(__dirname, '../../node_modules'), 'node_modules']
modules: [
path.join(__dirname, '../../node_modules'),
'node_modules',
path.join(__dirname, 'loaders')
]
},
output: {
path: outputPath,
Expand All @@ -92,69 +95,64 @@ module.exports = async function() {
rules: [
{
test: /\.scss$/,
loader: extractSass.extract({
use: [
{
loader: 'css-loader',
options: {
minimize: !isDev,
sourceMap: isDev
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: isDev ? 'inline' : false,
plugins: loader => {
const defaultPlugins = (config = {}) =>
[
config.autoprefixer === false
? null
: require('autoprefixer')({
browsers: ['last 2 versions', 'IE 11']
}),
config.lost === false ? null : require('lost'),
config['postcss-custom-media'] === false
? null
: require('postcss-custom-media'),
config['postcss-zindex'] === false
? null
: require('postcss-zindex'),
config['postcss-discard-duplicates'] === false
? null
: require('postcss-discard-duplicates'),
config['postcss-unique-selectors'] === false
? null
: require('postcss-unique-selectors'),
config['postcss-responsive-type'] === false
? null
: require('postcss-responsive-type')
].filter(i => i !== null)
// Allow custom PostCSS configuration
if (themeConfig.postCss) {
return themeConfig.postCss(loader, defaultPlugins)
}
loader: [
'extracted-loader',
...extractSass.extract({
use: [
{
loader: 'css-loader',
options: {
minimize: !isDev,
sourceMap: isDev
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: isDev ? 'inline' : false,
plugins: loader => {
const defaultPlugins = (config = {}) =>
[
config.autoprefixer === false
? null
: require('autoprefixer')({
browsers: ['last 2 versions', 'IE 11']
}),
config.lost === false ? null : require('lost'),
config['postcss-custom-media'] === false
? null
: require('postcss-custom-media'),
config['postcss-zindex'] === false
? null
: require('postcss-zindex'),
config['postcss-discard-duplicates'] === false
? null
: require('postcss-discard-duplicates'),
config['postcss-unique-selectors'] === false
? null
: require('postcss-unique-selectors'),
config['postcss-responsive-type'] === false
? null
: require('postcss-responsive-type')
].filter(i => i !== null)
// Allow custom PostCSS configuration
if (themeConfig.postCss) {
return themeConfig.postCss(loader, defaultPlugins)
}

return defaultPlugins()
return defaultPlugins()
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: isDev
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: isDev
}
}
],
// Use style-loader in development
fallback: {
loader: 'style-loader',
options: {
sourceMap: isDev,
importLoaders: 1
}
}
})
]
})
]
},
{
test: /\.(jpg|png|gif)$/,
Expand Down
43 changes: 43 additions & 0 deletions lib/webpack/loaders/extracted-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Based on github.com/sheerun/extracted-loader
/* eslint-disable no-irregular-whitespace */
module.exports = function(source) {
if (source.match('module.hot')) {
return source
}

return (
source +
`;
if (module.hot) {
var injectCss = function injectCss(prev, href) {
var link = prev.cloneNode();
link.href = href;
link.onload = link.onerror = function() {
prev.parentNode.removeChild(prev);
};
prev.stale = true;
prev.parentNode.insertBefore(link, prev.nextSibling);
};
module.hot.dispose(function() {
window.__webpack_reload_css__ = true;
});
module.hot.accept();
if (window.__webpack_reload_css__) {
module.hot.__webpack_reload_css__ = false;
console.log("[HMR] Reloading stylesheets...");
var prefix = ${this.options.output.publicPath
? `'${this.options.output.publicPath}'`
: `document.location.protocol + '//' + document.location.host`};
document
.querySelectorAll("link[href][rel=stylesheet]")
.forEach(function(link) {
if (!link.href.match(prefix) || link.stale) return;
injectCss(link, link.href.split("?")[0] + "?unix=${Number(
new Date()
)}");
});
}
}
`
)
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aviate",
"version": "0.0.14",
"version": "1.0.1",
"files": [
"lib",
"cli.js"
Expand Down Expand Up @@ -37,7 +37,7 @@
"chalk": "^2.1.0",
"cli-table": "^0.3.1",
"copy-dir": "^0.3.0",
"css-loader": "^0.28.4",
"css-loader": "^0.28.10",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"find-up": "^2.1.0",
Expand All @@ -48,17 +48,16 @@
"node-version": "^1.0.0",
"postcss-custom-media": "^6.0.0",
"postcss-discard-duplicates": "^2.1.0",
"postcss-loader": "^2.0.6",
"postcss-loader": "^2.1.0",
"postcss-responsive-type": "^1.0.0",
"postcss-unique-selectors": "^2.0.2",
"postcss-zindex": "^2.2.0",
"rimraf": "^2.6.1",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"styled-jsx": "^1.0.10",
"svg-spritemap-webpack-plugin": "^1.0.3",
"svgo-loader": "^1.2.1",
"webpack": "^3.5.5",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.6.0",
"webpack-format-messages": "^1.0.0"
},
Expand Down
Loading

0 comments on commit 010a644

Please sign in to comment.