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 #512 from Shopify/fix-asset-url
Browse files Browse the repository at this point in the history
Fix asset url generated in slate-tools start
  • Loading branch information
t-kelly authored Apr 25, 2018
2 parents fafb86f + 154f336 commit 8169df9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/slate-liquid-asset-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ module.exports = function liquidLoader(content) {
const key = `__LIQUID_LOADER_${getUniqueKey()}__`;

// We're on a dev server, replace the whole liquid expression
if (options['dev-server']) {
if (options.devServer) {
replacements[key] = file;
return key;
}

const fileRegex = new RegExp(escapeStringRegexp(file));

// Replace only the filename, keeping the liquid expression
return liquidExpr.replace(fileRegex, match => {
return liquidExpr.replace(fileRegex, (match) => {
replacements[key] = match;
return key;
});
Expand All @@ -64,7 +64,7 @@ module.exports = function liquidLoader(content) {
// Replace keys with a call to require(), correctly escaped
return `module.exports = ${JSON.stringify(keyedContent).replace(
llRegex,
match => {
(match) => {
const request = utils.urlToRequest(replacements[match]);
const path = utils.stringifyRequest(this, request);
Expand Down
16 changes: 7 additions & 9 deletions packages/slate-tools/cli/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const ora = require('ora');
const consoleControl = require('console-control-strings');
const clearConsole = require('react-dev-utils/clearConsole');
const openBrowser = require('react-dev-utils/openBrowser');
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
const env = require('@shopify/slate-env');
const {event} = require('@shopify/slate-analytics');

Expand Down Expand Up @@ -37,40 +36,39 @@ devServer.compiler.hooks.compile.tap('CLI', () => {

devServer.compiler.hooks.done.tap('CLI', (stats) => {
const statsJson = stats.toJson({}, true);
const messages = formatWebpackMessages(statsJson);

spinner.stop();
clearConsole();

if (messages.errors.length) {
if (statsJson.errors.length) {
event('slate-tools:start:compile-errors', {
errors: messages.errors,
errors: statsJson.errors,
version: packageJson.version,
});

console.log(chalk.red('Failed to compile.\n'));
console.log(config.paths.lib);

messages.errors.forEach((message) => {
statsJson.errors.forEach((message) => {
console.log(`${message}\n`);
});
}

if (messages.warnings.length) {
if (statsJson.warnings.length) {
event('slate-tools:start:compile-warnings', {
duration: statsJson.time,
warnings: messages.warnings,
warnings: statsJson.warnings,
version: packageJson.version,
});

console.log(chalk.yellow('Compiled with warnings.\n'));

messages.warnings.forEach((message) => {
statsJson.warnings.forEach((message) => {
console.log(`${message}\n`);
});
}

if (!messages.errors.length && !messages.warnings.length) {
if (!statsJson.errors.length && !statsJson.warnings.length) {
event('slate-tools:start:compile-success', {
duration: statsJson.time,
version: packageJson.version,
Expand Down
7 changes: 0 additions & 7 deletions packages/slate-tools/tools/webpack/config/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ module.exports = {
name: '[name].[ext]',
},
},
{
test: /^(?:(?!(css|scss|sass|js)).)*\.(liquid)$/,
exclude: commonExcludes(),
loader: `extract-loader!@shopify/slate-liquid-asset-loader?dev-server=${
isDevServer ? 'true' : 'false'
}`,
},
{
test: /(css|scss|sass)\.liquid$/,
exclude: commonExcludes(),
Expand Down
11 changes: 11 additions & 0 deletions packages/slate-tools/tools/webpack/config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ module.exports = merge(

module: {
rules: [
{
test: /^(?:(?!(css|scss|sass)).)*\.(liquid)$/,
exclude: commonExcludes(),
use: [
{loader: 'extract-loader'},
{
loader: '@shopify/slate-liquid-asset-loader',
options: {devServer: true},
},
],
},
{
test: /\.s[ac]ss$/,
exclude: commonExcludes(),
Expand Down
11 changes: 11 additions & 0 deletions packages/slate-tools/tools/webpack/config/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ module.exports = merge(

module: {
rules: [
{
test: /^(?:(?!(css|scss|sass|js)).)*\.(liquid)$/,
exclude: commonExcludes(),
use: [
{loader: 'extract-loader'},
{
loader: '@shopify/slate-liquid-asset-loader',
options: {devServer: false},
},
],
},
{
test: /\.s[ac]ss$/,
exclude: commonExcludes(),
Expand Down

0 comments on commit 8169df9

Please sign in to comment.