From 823b562b4bf78990a0931c5e07adb4980dd07626 Mon Sep 17 00:00:00 2001 From: dmbch Date: Wed, 14 Feb 2018 13:45:03 +0100 Subject: [PATCH] feat(build-config): update to latest alpha of extract text plugin --- packages/build-config/configs/build.js | 6 +++ packages/build-config/package.json | 2 +- .../sections/module-rules/postcss.js | 40 ++++++++++++++++++- yarn.lock | 5 +-- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/packages/build-config/configs/build.js b/packages/build-config/configs/build.js index 020904ca7..b7fdea77d 100644 --- a/packages/build-config/configs/build.js +++ b/packages/build-config/configs/build.js @@ -5,6 +5,7 @@ var path = require('path'); var webpack = require('webpack'); var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; var ServiceWorkerPlugin = require('../plugins/service-worker'); +var ExtractTextPlugin = require('extract-text-webpack-plugin'); var hopsConfig = require('hops-config'); @@ -58,6 +59,11 @@ module.exports = { plugins: [ new StatsWriterPlugin({ fields: null }), new ServiceWorkerPlugin(), + new ExtractTextPlugin({ + filename: getAssetPath('[name]-[contenthash:16].css'), + allChunks: true, + ignoreOrder: true, + }), new webpack.HashedModuleIdsPlugin(), new webpack.EnvironmentPlugin( Object.assign( diff --git a/packages/build-config/package.json b/packages/build-config/package.json index 385298c57..102e08e76 100644 --- a/packages/build-config/package.json +++ b/packages/build-config/package.json @@ -36,7 +36,7 @@ "babel-preset-react": "^6.24.1", "caniuse-lite": "^1.0.30000789", "css-loader": "^0.28.8", - "extract-text-webpack-plugin": "webpack-contrib/extract-text-webpack-plugin#next", + "extract-text-webpack-plugin": "^4.0.0-alpha.0", "file-loader": "^1.1.6", "find-up": "^2.1.0", "hops-config": "10.2.0", diff --git a/packages/build-config/sections/module-rules/postcss.js b/packages/build-config/sections/module-rules/postcss.js index 6469e3185..2220b56d0 100644 --- a/packages/build-config/sections/module-rules/postcss.js +++ b/packages/build-config/sections/module-rules/postcss.js @@ -4,6 +4,7 @@ var hopsConfig = require('hops-config'); var cssLoader = require.resolve('css-loader'); var postcssLoader = require.resolve('postcss-loader'); +var ExtractTextPlugin = require('extract-text-webpack-plugin'); var cssLoaderGlobalOptions = { importLoaders: 1, @@ -27,7 +28,44 @@ var postcssLoaderOptions = { ], }; -exports.default = { +exports.build = { + test: /\.css$/, + oneOf: [ + { + resourceQuery: /global/, + use: ExtractTextPlugin.extract({ + fallback: 'style-loader', + use: [ + { + loader: cssLoader, + options: cssLoaderGlobalOptions, + }, + { + loader: postcssLoader, + options: postcssLoaderOptions, + }, + ], + }), + }, + { + use: ExtractTextPlugin.extract({ + fallback: 'style-loader', + use: [ + { + loader: cssLoader, + options: cssLoaderLocalOptions, + }, + { + loader: postcssLoader, + options: postcssLoaderOptions, + }, + ], + }), + }, + ], +}; + +exports.develop = { test: /\.css$/, oneOf: [ { diff --git a/yarn.lock b/yarn.lock index 0cef3a825..608625adb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2910,12 +2910,11 @@ extglob@^2.0.4: snapdragon "^0.8.1" to-regex "^3.0.1" -extract-text-webpack-plugin@webpack-contrib/extract-text-webpack-plugin#next: +extract-text-webpack-plugin@^4.0.0-alpha.0: version "4.0.0-beta.0" - resolved "https://codeload.github.com/webpack-contrib/extract-text-webpack-plugin/tar.gz/a63fee296899ffc6e9c7c1a5ec760893c8c60445" + resolved "https://registry.yarnpkg.com/extract-text-webpack-plugin/-/extract-text-webpack-plugin-4.0.0-beta.0.tgz#f7361d7ff430b42961f8d1321ba8c1757b5d4c42" dependencies: async "^2.4.1" - glob "^7.1.2" loader-utils "^1.1.0" schema-utils "^0.4.5" webpack-sources "^1.1.0"