Skip to content

Commit

Permalink
fix: assets relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 7, 2020
1 parent 32ea2f4 commit b3bf9e8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 74 deletions.
3 changes: 1 addition & 2 deletions core/webpack-compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"main": "dist/index.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"browser": "dist/bundle.js",
"files": [
"files": [
"dist/",
"package.json",
"README.md",
Expand Down
5 changes: 3 additions & 2 deletions core/webpack-compile/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type CompileRunProps = CompileProps & {

const createConfig = (options: CompileRunProps): webpack.Configuration => {
const { webPack, presets, configPath, mode, outputFolder } = options;
const distFolder = path.resolve(__dirname, '../dist');
const plugins = [
new LoaderPlugin({
config: configPath,
Expand All @@ -35,7 +36,7 @@ const createConfig = (options: CompileRunProps): webpack.Configuration => {
},

output: {
path: path.resolve(__dirname, '../dist'),
path: distFolder,
filename: 'bundle.js',
libraryTarget: 'umd',
globalObject: 'this',
Expand All @@ -48,7 +49,7 @@ const createConfig = (options: CompileRunProps): webpack.Configuration => {
...(webPack || {}),
},
presets,
{ outputFolder },
{ outputFolder, distFolder },
);

//add all the aliases to avoid double loading of packages
Expand Down
149 changes: 79 additions & 70 deletions core/webpack-configs/src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,89 @@
import * as path from 'path';
import { PresetType, PresetOptions } from '../types';

export const react: PresetType = (options?: PresetOptions) => ({
performance: { hints: false },
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
presets: [
[require.resolve('@babel/preset-env'), { modules: 'commonjs' }],
require.resolve('@babel/preset-react'),
],
export const react: PresetType = (options?: PresetOptions) => {
return {
performance: { hints: false },
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
require.resolve('@babel/preset-env'),
{ modules: 'commonjs' },
],
require.resolve('@babel/preset-react'),
],
},
},
],
},
{
test: /\.(eot|md|svg|ico|jpg|jpeg|png|gif|ttf|woff|woff2|pdf|mp4|web|wav|mp3|m4a|aac|oga)$/i,
exclude: [/node_modules/],
loader: 'url-loader',
options: {
limit: 25000,
name: '[name].[hash].[ext]',
publicPath: '/static',
outputPath: path.relative(
options?.distFolder || process.cwd(),
path.resolve(options?.outputFolder || process.cwd(), 'static'),
),
},
],
},
{
test: /\.(eot|md|svg|ico|jpg|jpeg|png|gif|ttf|woff|woff2|pdf|mp4|web|wav|mp3|m4a|aac|oga)$/i,
exclude: [/node_modules/],
loader: 'url-loader',
options: {
limit: 25000,
name: '[name].[hash].[ext]',
publicPath: '/static',
outputPath: options?.outputFolder,
},
},
{
test: /\.(ts|tsx)$/,
exclude: [/node_modules/],
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
{
test: /\.(ts|tsx)$/,
exclude: [/node_modules/],
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
},
},
},
],
},
{
test: /\.txt$/i,
use: require.resolve('raw-loader'),
},
{
test: /\.(md|mdx)$/i,
exclude: [/node_modules/],
loader: 'babel-loader',
options: {
presets: [
[require.resolve('@babel/preset-env'), { modules: 'commonjs' }],
require.resolve('@babel/preset-react'),
],
},
},
{
test: /\.(md|mdx)$/i,
exclude: [/node_modules/],
loader: '@component-controls/loader/loader',
options: {
mdx: {
transformMDX: true,
{
test: /\.txt$/i,
use: require.resolve('raw-loader'),
},
{
test: /\.(md|mdx)$/i,
exclude: [/node_modules/],
loader: 'babel-loader',
options: {
presets: [
[require.resolve('@babel/preset-env'), { modules: 'commonjs' }],
require.resolve('@babel/preset-react'),
],
},
},
},
{
test: /\.(story|stories|doc|docs).(js|jsx|ts|tsx)$/,
loader: '@component-controls/loader/loader',
exclude: [/node_modules/],
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
});
{
test: /\.(md|mdx)$/i,
exclude: [/node_modules/],
loader: '@component-controls/loader/loader',
options: {
mdx: {
transformMDX: true,
},
},
},
{
test: /\.(story|stories|doc|docs).(js|jsx|ts|tsx)$/,
loader: '@component-controls/loader/loader',
exclude: [/node_modules/],
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
};
};
3 changes: 3 additions & 0 deletions core/webpack-configs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export type RuleType = string | RuleOptions;
export type RuleTypes = RuleType[];

export interface PresetOptions {
//output folder for static assets
outputFolder?: string;
//dist folder where bundle is output
distFolder?: string;
}

export type PresetCallback = (options?: PresetOptions) => Configuration;
Expand Down

0 comments on commit b3bf9e8

Please sign in to comment.