2.0.5 • Published 1 month ago

@flatjs/forge-plugin-styling v2.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

The flatjs plugin @flatjs/forge-plugin-styling

A plugin for compile less, sass, css for forge compiler. Note: the sass maybe will broken in macos node environment. we need to using node-sass.

Features

  • A plugin for compile less, sass, css for @flatjs/forge.
  • Use this plugin is suite for compile wechat miniprogram modular is better.
  • If we need to modular build react UI components(with stylings) recommend use rollup-plugin-postcss enable CSS modules for .module.css .module.sss .module.scss .module.sass .module.styl .module.stylus .module.less files.

Installation

$ npm i --save @flatjs/forge-plugin-styling

Configuration

export const testCompile = async (
  input: string | string[],
  options: forgePluginStylingOptions,
  distFolder?: string,
): Promise<boolean> => {
  // Note: `forgePluginStyling` is plugin of @flatjs/forge,
  // in most case we will use `ForgeBuildOptions` as build options.
  const stylingPlugin = forgePluginStyling(options);
  return startBuild(options.projectCwd, options.projectCwd, {
    input,
    output: {
      distFolder: distFolder || options.format,
      format: options.format,
      cleanDistFolder: false,
      // `@flatjs/forge` for javascript only.
      sourcemap: options.sourceMap,
      // we must set sourcemap: true, while sourcemapPathTransform
      sourcemapPathTransform(_relativeSourcePath: string, sourcemapPath: string) {
        return sourcemapPath;
      },
    },
    plugin: {
      extraPlugins: [stylingPlugin],
    },
  });
};

Usage

simple

const result = await testCompile('src/index.ts', {
  projectCwd,
  use: ['less', 'sass'],
  format: 'cjs',
  styleOutputExt: '.css',
});

See more

css

const result = await testCompile(['src/multi-entry-two.ts', 'src/multi-entry-one.ts'], {
  projectCwd,
  format: 'cjs',
});

See more

less

const result = await testCompile('src/index.ts', {
  projectCwd,
  use: ['less'],
  format: 'cjs',
});

See more

sass

const result = await testCompile('src/index.ts', {
  projectCwd,
  use: ['sass'],
  format: 'cjs',
  styleOutputExt: '.css',
});

See more

sourcemap

sourcemap.test.ts sourceMap:inline

// will generate inline sourcemap `css`.
const result = await testCompile('src/css/sourcemap.ts', {
  projectCwd,
  format: 'umd',
  sourceMap: 'inline',
});
// will generate inline sourcemap `less`.
const result1 = await testCompile('src/less/sourcemap.ts', {
  projectCwd,
  format: 'umd',
  sourceMap: 'inline',
});
// will generate inline sourcemap `sass`.
const result2 = await testCompile('src/sass/sourcemap.ts', {
  projectCwd,
  format: 'umd',
  sourceMap: 'inline',
});

sourcemap.test.ts sourceMap:true

// should generate sourcemap file `css`
const result = await testCompile('src/css/sourcemap-with-file.ts', {
  projectCwd,
  format: 'umd',
  sourceMap: true,
});

// should generate sourcemap file `less`
const lessOpt: Less.Options = {
  sourceMap: {
    sourceMapFileInline: true,
  },
};
const result = await testCompile('src/less/sourcemap-with-file.ts', {
  projectCwd,
  format: 'umd',
  // Note the final output sourceMap file.
  sourceMap: true,
  use: [['less', lessOpt]],
});

// should generate sourcemap file `sass`
const sassOpts: Options = {
  sourceMap: true,
};
const result = await testCompile('src/sass/sourcemap-with-file.ts', {
  projectCwd,
  format: 'umd',
  // Note the final output sourceMap file.
  sourceMap: true,
  use: [['sass', sassOpts]],
});

See more

wxss

const result = await testCompile(
  ['src/page1/index.ts', 'src/page2/index.ts'],
  {
    projectCwd,
    use: ['less'],
    format: 'cjs',
    autoAppendToModule: false,
    styleOutputExt: '.wxss',
  },
  'miniprogram',
);

See more

References

for sass processor

  • npm i node-sass
  • npm rebuild node-sass (if required(node-sass) failed)
2.1.0-next.2

1 month ago

2.1.0-next.1

1 month ago

2.1.0-next.0

1 month ago

2.0.5

2 months ago

2.0.4

2 months ago

2.0.3

3 months ago

2.0.2

5 months ago

2.0.1

5 months ago

2.0.0

6 months ago

1.8.1-next.34

10 months ago

1.8.1-next.33

11 months ago

1.8.1-next.36

10 months ago

1.8.1-next.35

10 months ago

1.8.1-next.38

10 months ago

1.8.1-next.37

10 months ago

1.8.1-next.39

9 months ago

1.8.1-next.41

9 months ago

1.8.1-next.40

9 months ago

1.8.1-next.43

8 months ago

1.8.1-next.42

8 months ago

1.8.1-next.44

7 months ago

2.0.0-next.2

7 months ago

2.0.0-next.3

7 months ago

2.0.0-next.1

7 months ago

1.8.1-next.29

11 months ago

1.8.1-next.28

11 months ago

1.8.1-next.30

11 months ago

1.8.1-next.32

11 months ago

1.8.1-next.31

11 months ago

1.7.1-next.0

1 year ago

1.7.1-next.2

1 year ago

1.7.1-next.1

1 year ago

1.8.1-next.21

12 months ago

1.8.1-next.20

12 months ago

1.8.1-next.23

11 months ago

1.7.1-next.4

1 year ago

1.6.0

1 year ago

1.8.1-next.22

11 months ago

1.7.1-next.3

1 year ago

1.8.1-next.25

11 months ago

1.8.1-next.24

11 months ago

1.7.1-next.5

1 year ago

1.8.1-next.27

11 months ago

1.8.1-next.7

1 year ago

1.8.1-next.26

11 months ago

1.8.1-next.6

1 year ago

1.8.1-next.9

12 months ago

1.8.1-next.8

1 year ago

1.7.2

12 months ago

1.7.0

1 year ago

1.8.1-next.10

12 months ago

1.8.1-next.12

12 months ago

1.8.1-next.11

12 months ago

1.8.1-next.14

12 months ago

1.8.1-next.16

12 months ago

1.8.1-next.15

12 months ago

1.8.1-next.18

12 months ago

1.8.1-next.17

12 months ago

1.8.1-next.19

12 months ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.17

2 years ago

1.3.13

2 years ago

1.3.14

2 years ago

1.3.12

2 years ago

1.3.11

2 years ago

1.3.6

2 years ago

1.3.9

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.0

2 years ago

1.2.101

2 years ago

1.2.100

2 years ago

1.2.98

2 years ago

1.2.99

2 years ago

1.2.96

2 years ago

1.2.97

2 years ago

1.2.95

2 years ago

1.2.94

3 years ago

1.2.93

3 years ago

1.2.90

3 years ago

1.2.83

3 years ago

1.2.82

3 years ago

1.2.81

3 years ago

1.2.80

3 years ago

1.2.79

3 years ago

1.2.78

3 years ago

1.2.77

3 years ago

1.2.76

3 years ago

1.2.75

3 years ago

1.2.74

3 years ago

1.2.73

3 years ago

1.2.70

3 years ago

1.2.69

3 years ago

1.2.68

3 years ago

1.2.67

3 years ago

1.2.66

3 years ago

1.2.65

3 years ago