Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
feat: 增加 @ 作为 src的别名
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Aug 11, 2019
1 parent d1a91a3 commit f34ac2e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/remax-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"lodash": "^4.17.11",
"postcss-px2units": "^0.2.0",
"rollup": "^1.16.0",
"rollup-plugin-alias": "^1.5.2",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-clear": "^2.0.7",
"rollup-plugin-commonjs": "^10.0.0",
Expand Down
19 changes: 18 additions & 1 deletion packages/remax-cli/src/build/rollupConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { RollupOptions, RollupWarning } from 'rollup';
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import postcss from 'rollup-plugin-postcss';
import progress from 'rollup-plugin-progress';
import clear from 'rollup-plugin-clear';
import alias from 'rollup-plugin-alias';
import pxToUnits from 'postcss-px2units';
import getEntries from '../getEntries';
import getCssModuleConfig from '../getCssModuleConfig';
Expand Down Expand Up @@ -50,6 +52,20 @@ export default function rollupConfig(
const cssModuleConfig = getCssModuleConfig(options.cssModules);

const plugins = [
alias({
resolve: [
'',
'.ts',
'.js',
'.tsx',
'.jsx',
'/index.js',
'/index.jsx',
'/index.ts',
'/index.tsx',
],
'@': path.resolve(options.cwd, 'src'),
}),
commonjs({
include: /node_modules/,
namedExports: {
Expand Down Expand Up @@ -110,7 +126,8 @@ export default function rollupConfig(
if (!input) {
return input;
}
input

input = input
.replace(/^demo\/src\//, '')
.replace(/\.less$/, '.less.js')
.replace(/\.ts$/, '.js')
Expand Down
1 change: 1 addition & 0 deletions packages/remax-cli/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare module 'rollup-plugin-json';
declare module 'rollup-plugin-node-resolve';
declare module 'rollup-plugin-progress';
declare module 'rollup-plugin-clear';
declare module 'rollup-plugin-alias';
declare module 'rollup-plugin-typescript';
declare module 'postcss-px2units';
declare module '@babel/helper-module-imports';
Expand Down
12 changes: 12 additions & 0 deletions packages/remax-cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5652,6 +5652,13 @@ [email protected]:
rc-util "4.x"
rmc-align "~1.0.0"

rollup-plugin-alias@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-1.5.2.tgz#f15a1cc8ee0debf74ab5c2bb68a944a66b568411"
integrity sha512-ODeZXhTxpD48sfcYLAFc1BGrsXKDj7o1CSNH3uYbdK3o0NxyMmaQPTNgW+ko+am92DLC8QSTe4kyxTuEkI5S5w==
dependencies:
slash "^3.0.0"

rollup-plugin-babel@^4.3.2:
version "4.3.3"
resolved "https://registry.npm.taobao.org/rollup-plugin-babel/download/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa"
Expand Down Expand Up @@ -5883,6 +5890,11 @@ slash@^2.0.0:
resolved "https://registry.npm.taobao.org/slash/download/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
integrity sha1-3lUoUaF1nfOo8gZTVEL17E3eq0Q=

slash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

snapdragon-node@^2.0.1:
version "2.1.1"
resolved "https://registry.npm.taobao.org/snapdragon-node/download/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
Expand Down

0 comments on commit f34ac2e

Please sign in to comment.