Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #647 from Shopify/copy-images-fonts
Browse files Browse the repository at this point in the history
Copy the contents of src/assets/images and src/assets/fonts
  • Loading branch information
t-kelly authored Jun 26, 2018
2 parents 1193e0d + 3e1cc0d commit f7b3e6b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 37 deletions.
50 changes: 47 additions & 3 deletions packages/slate-tools/slate-tools.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ module.exports = generate({
},
{
id: 'static',
default: resolveTheme('src/assets/static'),
items: [
{
id: 'src',
default: resolveTheme('src/assets/static'),
},
{
id: 'dist',
default: resolveTheme('dist/assets'),
},
],
},
{
id: 'scripts',
Expand All @@ -97,6 +106,32 @@ module.exports = generate({
id: 'svgs',
default: resolveTheme('src/assets/svg'),
},
{
id: 'fonts',
items: [
{
id: 'src',
default: resolveTheme('src/assets/fonts'),
},
{
id: 'dist',
default: resolveTheme('dist/assets'),
},
],
},
{
id: 'images',
items: [
{
id: 'src',
default: resolveTheme('src/assets/images'),
},
{
id: 'dist',
default: resolveTheme('dist/assets'),
},
],
},
{
id: 'locales',
items: [
Expand Down Expand Up @@ -156,8 +191,17 @@ module.exports = generate({
default: resolveTheme('dist/assets'),
},
{
id: 'snippetsOutput',
default: resolveTheme('dist/snippets'),
id: 'snippets',
items: [
{
id: 'src',
default: resolveTheme('src/snippets'),
},
{
id: 'dist',
default: resolveTheme('dist/snippets'),
},
],
},
{
id: 'userShopifyConfig',
Expand Down
67 changes: 33 additions & 34 deletions packages/slate-tools/tools/webpack/config/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const commonExcludes = require('../common-excludes');
const babelLoader = require('../loaders/babel-loader');
const config = require('../../../slate-tools.config');
const {paths, regex} = require('../../../slate-tools.config');
const {entrypointFiles} = require('../entrypoints');

const paths = config.paths;

const extractLiquidStyles = new ExtractTextPlugin(
'[name].styleLiquid.scss.liquid',
);
Expand All @@ -35,29 +33,29 @@ function contextReplacementPlugins() {
),
];

if (fs.existsSync(paths.static)) {
if (fs.existsSync(paths.static.src)) {
plugins.push(
new webpack.ContextReplacementPlugin(
/__appstatic__/,
replaceCtxRequest(paths.static),
replaceCtxRequest(paths.static.src),
),
);
}

if (fs.existsSync(paths.images)) {
if (fs.existsSync(paths.images.src)) {
plugins.push(
new webpack.ContextReplacementPlugin(
/__appimages__/,
replaceCtxRequest(paths.images),
replaceCtxRequest(paths.images.src),
),
);
}

if (fs.existsSync(paths.fonts)) {
if (fs.existsSync(paths.fonts.src)) {
plugins.push(
new webpack.ContextReplacementPlugin(
/__appfonts__/,
replaceCtxRequest(paths.fonts),
replaceCtxRequest(paths.fonts.src),
),
);
}
Expand All @@ -68,19 +66,19 @@ function contextReplacementPlugins() {
module.exports = {
context: paths.src,

entry: Object.assign(entrypointFiles(), config.paths.entrypoints),
entry: Object.assign(entrypointFiles(), paths.entrypoints),

output: {
filename: '[name].js',
path: config.paths.assetsOutput,
path: paths.assetsOutput,
},

resolveLoader: {
modules: [
config.paths.nodeModules.self,
config.paths.nodeModules.repo,
config.paths.nodeModules.app,
config.paths.webpack,
paths.nodeModules.self,
paths.nodeModules.repo,
paths.nodeModules.app,
paths.webpack,
],
},

Expand All @@ -99,15 +97,15 @@ module.exports = {
loader: 'file-loader',
},
{
test: config.regex.images,
test: regex.images,
exclude: commonExcludes(),
use: [
{loader: 'file-loader', options: {name: '[name].[ext]'}},
{loader: 'img-loader'},
],
},
{
test: config.regex.static,
test: regex.static,
exclude: commonExcludes('assets/styles'),
loader: 'file-loader',
options: {
Expand Down Expand Up @@ -137,30 +135,31 @@ module.exports = {

new CopyWebpackPlugin([
{
from: config.paths.svgs,
to: `${config.paths.snippetsOutput}/[name].liquid`,
from: paths.svgs,
to: `${paths.snippets.dist}/[name].liquid`,
},
]),

new CopyWebpackPlugin([
{
from: config.paths.locales.src,
to: config.paths.locales.dist,
from: paths.static.src,
to: paths.static.dist,
},
{
from: paths.images.src,
to: paths.images.dist,
},
]),

new CopyWebpackPlugin([
{
from: config.paths.settings.src,
to: config.paths.settings.dist,
from: paths.fonts.src,
to: paths.fonts.dist,
},
{
from: paths.locales.src,
to: paths.locales.dist,
},
{
from: paths.settings.src,
to: paths.settings.dist,
},
]),

new WriteFileWebpackPlugin({
test: /\.(png|jpg|gif|scss|jpeg)/,
log: false,
}),

new WriteFileWebpackPlugin({
test: /^(?:(?!hot-update.json$).)*\.(liquid|json)$/,
log: false,
Expand Down

0 comments on commit f7b3e6b

Please sign in to comment.