|
|
@@ -15,26 +15,34 @@ const BabelMinifyPlugin = require( 'babel-minify-webpack-plugin' );
|
|
|
|
|
|
module.exports = function snippetAdapter( data ) {
|
|
|
const snippetConfig = readSnippetConfig( data.snippetSource.js );
|
|
|
+ const outputPath = path.join( data.outputPath, data.snippetPath );
|
|
|
|
|
|
const webpackConfig = getWebpackConfig( {
|
|
|
entry: data.snippetSource.js,
|
|
|
- outputPath: path.join( data.outputPath, data.snippetPath ),
|
|
|
+ outputPath,
|
|
|
language: snippetConfig.language,
|
|
|
minify: data.options.production
|
|
|
} );
|
|
|
|
|
|
return runWebpack( webpackConfig )
|
|
|
.then( () => {
|
|
|
+ const wasCSSGenerated = fs.existsSync( path.join( outputPath, 'snippet.css' ) );
|
|
|
+ const cssFiles = [
|
|
|
+ path.join( data.basePath, 'assets', 'snippet-styles.css' )
|
|
|
+ ];
|
|
|
+
|
|
|
+ // CSS may not be generated by Webpack if a snippet's JS file didn't import any SCSS files.
|
|
|
+ if ( wasCSSGenerated ) {
|
|
|
+ cssFiles.unshift( path.join( data.relativeOutputPath, data.snippetPath, 'snippet.css' ) );
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
html: fs.readFileSync( data.snippetSource.html ),
|
|
|
assets: {
|
|
|
js: [
|
|
|
path.join( data.relativeOutputPath, data.snippetPath, 'snippet.js' )
|
|
|
],
|
|
|
- css: [
|
|
|
- path.join( data.relativeOutputPath, data.snippetPath, 'snippet.css' ),
|
|
|
- path.join( data.basePath, 'assets', 'snippet-styles.css' )
|
|
|
- ]
|
|
|
+ css: cssFiles
|
|
|
}
|
|
|
};
|
|
|
} );
|