Skip to content

Commit

Permalink
inject style-inject as a module
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jan 31, 2018
1 parent e255076 commit beef7c5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"promise.series": "^0.2.0",
"reserved-words": "^0.1.2",
"rollup-pluginutils": "^2.0.1",
"style-inject": "^0.2.0"
"style-inject": "^0.3.0"
},
"xo": {
"extends": "rem",
Expand Down
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path'
import fs from 'fs-extra'
import { createFilter } from 'rollup-pluginutils'
import styleInject from 'style-inject'
import Concat from 'concat-with-sourcemaps'
import Loaders from './loaders'
import { normalizePath } from './utils'
Expand Down Expand Up @@ -64,11 +63,6 @@ export default (options = {}) => {
return {
name: 'postcss',

intro() {
if (!postcssLoaderOptions.inject || postcssLoaderOptions.extract) return
return styleInject.toString().replace('styleInject', '__$$$$styleInject')
},

async transform(code, id) {
if (!filter(id) || !loaders.isSupported(id)) {
return null
Expand Down
4 changes: 3 additions & 1 deletion src/postcss-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import findPostcssConfig from 'postcss-load-config'
import reserved from 'reserved-words'
import { localRequire, normalizePath } from './utils'

const styleInjectPath = require.resolve('style-inject/dist/style-inject.es')

function loadConfig(id, { ctx: configOptions, path: configPath }) {
const handleError = err => {
if (err.message.indexOf('No PostCSS Config found') === -1) {
Expand Down Expand Up @@ -131,7 +133,7 @@ export default {
};`
}
if (!shouldExtract && shouldInject) {
output += `\n__$$styleInject(css${
output += `\nimport styleInject from '${styleInjectPath}';\nstyleInject(css${
Object.keys(options.inject).length > 0 ?
`,${JSON.stringify(options.inject)}` :
''
Expand Down

0 comments on commit beef7c5

Please sign in to comment.