Skip to content

Commit

Permalink
Merge pull request #95 from yoriiis/esm
Browse files Browse the repository at this point in the history
Migrate to ESM
  • Loading branch information
yoriiis authored Oct 2, 2023
2 parents 4b25dc0 + 56ca228 commit 937e896
Show file tree
Hide file tree
Showing 15 changed files with 994 additions and 1,780 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ jobs:
uses: yoriiis/actions/.github/workflows/lint.yml@main
with:
stylelint-status: false
eslint-config: 'config/.eslintrc.cjs'
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ First, let's add the plugin to the webpack configuration.
**webpack.config.js**

```js
const ChunksWebpackPlugin = require('chunks-webpack-plugin');
import ChunksWebpackPlugin from 'chunks-webpack-plugin';

module.exports = {
export default {
plugins: [new ChunksWebpackPlugin()]
};
```
Expand Down Expand Up @@ -114,7 +114,7 @@ Default:
Tells the plugin whether to personalize the default template for the HTML `<style>` tags. For example, add additional attributes or a CDN prefix.

```js
module.exports = {
export default {
plugins: [
new ChunksWebpackPlugin({
templateStyle: (name) => `<link rel="stylesheet" href="https://cdn.domain.com${name}" />`
Expand All @@ -140,7 +140,7 @@ Default:
Tells the plugin whether to personalize the default template for the HTML `<script>` tags. For example, add additional attributes or a CDN prefix.

```js
module.exports = {
export default {
plugins: [
new ChunksWebpackPlugin({
templateScript: (name) => `<script defer src="https://cdn.domain.com${name}"></script>`
Expand All @@ -162,7 +162,7 @@ Default: `false`
Tells the plugin whether to generate the `chunks-manifest.json`. The file contains the list of all chunks grouped by entry points. See the [chunks-manifest.json example](example/dist/chunks-manifest.json).

```js
module.exports = {
export default {
plugins: [
new ChunksWebpackPlugin({
generateChunksManifest: true
Expand All @@ -184,7 +184,7 @@ Default: `true`
Tells the plugin whether to generate the HTML files.

```js
module.exports = {
export default {
plugins: [
new ChunksWebpackPlugin({
generateChunksFiles: false
Expand All @@ -206,10 +206,13 @@ module.exports = {
Example of the webpack configuration with multiple entry points which share common code with the `splitChunks` option.

```js
const ChunksWebpackPlugin = require('chunks-webpack-plugin');
const path = require('path');
import ChunksWebpackPlugin from 'chunks-webpack-plugin';
import path from 'path';

module.exports = {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
entry: {
home: 'home.js',
news: 'news.js'
Expand Down
File renamed without changes.
12 changes: 10 additions & 2 deletions config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module.exports = {
export default {
moduleFileExtensions: ['js', 'ts'],
modulePaths: ['<rootDir>/src'],
rootDir: '../',
resetModules: true,
transform: {
'\\.(js|ts)$': 'ts-jest'
'\\.(js|ts)$': [
'ts-jest',
{
diagnostics: {
// Disable error reporting with import assertions
ignoreCodes: ['TS2821']
}
}
]
},
moduleNameMapper: {
'^@src(.*)$': '<rootDir>/src$1'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/dist/js/app-b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/dist/js/app-c.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/dist/js/lib-dynamic.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/dist/js/shared/app-a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/src/js/app-c.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import 'vlitejs';
import 'sanitize.css';
import '../css/app-c.css';
(async () => {
await import(/* webpackChunkName: "lib-dynamic" */ '../lib/dynamic');
await import(/* webpackChunkName: "lib-dynamic" */ '../lib/dynamic.js');
})();
16 changes: 10 additions & 6 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const ChunksWebpackPlugin = require('../lib/index.js');
import path from 'path';
import { fileURLToPath } from 'url';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserJSPlugin from 'terser-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import ChunksWebpackPlugin from '../lib/index.js';

module.exports = (env, argv) => {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default (env, argv) => {
const isProduction = argv.mode === 'production';

return {
Expand Down
Loading

0 comments on commit 937e896

Please sign in to comment.