Last active
June 28, 2018 08:57
-
-
Save MrKou47/d5ba3e38b6f69deedc9b67ea7350973c to your computer and use it in GitHub Desktop.
css-loader-with-optionPlugin example
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
if (process.env.NODE_ENV === undefined) { | |
process.env.NODE_ENV = 'development'; | |
} | |
const webpack = require('webpack'); | |
const brfs = require('brfs'); | |
const autoprefixer = require('autoprefixer'); | |
const libraryName = process.env.NODE_ENV === 'development' ? '[name]' : '[name]_[chunkhash]'; | |
const styleLoaderName = 'style-loader'; | |
const cssLoaderName = 'css-loader-bbq'; | |
const styleQuery = 'modules&localIdentName=[name]__[local]___[hash:base64:5]&importLoaders=1'; | |
const brfsLoader = { | |
test: [ | |
require.resolve('./src/client/Home'), | |
], | |
loader: 'transform-loader?0', | |
enforce: 'post', | |
}; | |
const postcssLoader = { | |
loader: 'postcss-loader', | |
options: { | |
plugins: [ | |
autoprefixer({ | |
browsers: [ | |
'>1%', | |
'last 4 versions', | |
'not ie < 8', | |
], | |
}), | |
], | |
}, | |
}; | |
const clientPlugins = [ | |
new webpack.LoaderOptionsPlugin({ | |
options: { | |
context: config.basedir, | |
transforms: [ | |
file => brfs(file, { parserOpts: { allowImportExportEverywhere: true } }), | |
], | |
}, | |
}), | |
]; | |
module.exports = [{ | |
entry: { | |
frameworks_create_entry: [require.resolve('./src/frameworks/createEntry')], | |
}, | |
output: { library: libraryName, crossOriginLoading: 'anonymous' }, | |
module: { | |
rules: [{ | |
test: /\.css$/, | |
include: 'src/', | |
use: [ | |
styleLoaderName, | |
`${cssLoaderName}?${styleQuery}`, | |
postcssLoader, | |
], | |
}], | |
}, | |
}, { | |
entry: { | |
client: require.resolve('./src/client/client'), | |
plain: require.resolve('./src/plain/client'), | |
palette: require.resolve('./src/palette/client'), | |
}, | |
module: { | |
rules: [{ | |
test: /\.css$/, | |
include: 'src/', | |
use: [ | |
`${cssLoaderName}/locals?${styleQuery}&cssText`, | |
postcssLoader, | |
], | |
}], | |
}, | |
output: { crossOriginLoading: 'anonymous' }, | |
plugins: clientPlugins, | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment